Comments (9)
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.
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.
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.
added a pull request
from php7-compat.
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.
could you comment on why this works better than my fix? I'm curious
from php7-compat.
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.
I haven't forgotten about this issue, but unfortunately I've also not had time to fix it yet.
from php7-compat.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php7-compat.