Giter Club home page Giter Club logo

Comments (9)

dkloke avatar dkloke commented on June 26, 2024 1

I needed to add it to get some legacy code to work, I can't justify it beyond that. I just copied the current mysql_pconnect() behavior and that worked for my case.

I briefly pondered the $new_link problem but couldn't find an easy agnostic solution. As far as I can tell, mysqli_connect() returns a new $link->thread_id every time it's called, whereas mysql_connect() reuses similar resource id connections unless forced with $new_link.

I suppose one could hash $server, $user, and $password values in parallel with $_php7_compat_global_db_link to eliminate redundant connections, but this compromise security.

If the legacy code being made compatible is already managing multiple links explicitly, $_php7_compat_global_db_link should (?) be superfluous (but not unsafe) for those cases, because $_php7_compat_global_db_link only fills in for unspecified $link parameters.

I didn't initially see your proposed change here : dafuki@a5d94fa. I would say that new lines 67-71 aren't necessary because $link is never used before being changed, just keep old line 67.

It may be more similar to legacy PHP-Mysql behavior to unconditionally replace $_php7_compat_global_db_link every time a new connection is made, because PHP-Mysql uses the most recent connection for operations where $link is unspecified. This could forgive sloppy but otherwise working code.

&& !$new_link is correct but perhaps unforgiving of code that needlessly set $new_link to true for an otherwise single connection later used as implied default.

I have not written PHP in a long time and may be overthinking kindness to poor legacy code.

from php7-compat.

kdkd avatar kdkd commented on June 26, 2024 1

I submitted pull request #7 just to get mysql_connect() working as well as mysql_pconnect() does, but I believe you're correct that the actual legacy mysql extension's behavior is slightly different. In my case it didn't matter though.

from php7-compat.

kitserve avatar kitserve commented on June 26, 2024

No, this wasn't intentional. Good catch! If you're able to come up with a fix, that would be great. Otherwise I'll take a look when I get the chance - bit overloaded with other tasks at the moment.

from php7-compat.

dafuki avatar dafuki commented on June 26, 2024

added a pull request

from php7-compat.

dkloke avatar dkloke commented on June 26, 2024

Thank you for this useful and convenient library.

I used the following patch to mysql_connect to mimic the behavior of mysql_pconnect, which only sets the first new link to the global convenience link:

//		return mysqli_connect( $server, $user, $password );

		$link = mysqli_connect( $server, $user, $password );

		global $_php7_compat_global_db_link; // should be at beginning of proc
		if( !$_php7_compat_global_db_link ) $_php7_compat_global_db_link = $link;

		return $link;

from php7-compat.

dafuki avatar dafuki commented on June 26, 2024

could you comment on why this works better than my fix? I'm curious

from php7-compat.

dafuki avatar dafuki commented on June 26, 2024

I'm trying to make sure I'm getting you right (not feeling well atm), but if there is no use of new_link, it's probably not a perfect match for the legacy function.
We could try and see the actual code logic for the mysql_connect function in the C sources. Might fix the dilemma.
The code between 67-71 is to avoid creating a global variable when it is not needed. But I didn't get the chance to test the code, and still can't.
👍 for the comment

from php7-compat.

kitserve avatar kitserve commented on June 26, 2024

I haven't forgotten about this issue, but unfortunately I've also not had time to fix it yet.

from php7-compat.

kitserve avatar kitserve commented on June 26, 2024

Thanks for this fix. I'm leaving the issue open to remind myself to review it in more depth when (if?) I get the chance. For now the proposed changes sound like a good compromise if they allow most existing code to work without modification.

from php7-compat.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.