ID: 32866 Updated by: [EMAIL PROTECTED] Reported By: kevin at hatry dot com -Status: Open +Status: Bogus Bug Type: MySQL related Operating System: windows XP + linux PHP Version: 4.3.11 New Comment:
Change false to true in mysql_connect() and it will work like you want it to work. Still not a bug. Previous Comments: ------------------------------------------------------------------------ [2005-04-28 12:26:33] kevin at hatry dot com Description: ------------ I originally posted this info on follow up of bug id 30525 but it has been reported as bogus and i dont think the problem has been fully understood. Please *do* try to understand the problem here as there *is* one ! PHP version used : -> php 4.3.11 on win32 with the bundled 3.23.49 mysql client -> php 4.3.11 on linux kernel 2.4.29 with external 4.1.11 mysql client both with apache 1.3.33 and with the cli binary. Preface : I *do* understand that by default MySQL connections are shared in PHP. I also note that in older versions a single mysql_close() would close all of the links but that there now appears to be reference counting before finally closing the TCP connection which is a better thing for me. The problem is : It seems that affecting a value or 'unset'ing a variable of type mysql resource or living the function in which the variable was created calls mysql_close on that variable (and so reduces the reference) even if a previous call was already made on that variable. So the reference count becomes wrong. So it is very hard to keep track of the real status (connected, not connected, of type mysql, of type unknown) of a mysql resource. The reproduce code is quite simple but is, i think, a typical way of programming : you have a function (or class) that query mysql by creating its own resource. Normally, with this version of PHP, the call to mysql_close should not close the shared connection so the code is ok to use. But with the bug a second call to mysl_close is made when the function returns. A last note : the same bug can be found if, instead of calling the function "do_something_in_mysql" we do $link1 = -1; after the line "mysql_close($link1);". Thank you for your time, i hope you will see the bug this time. Reproduce code: --------------- <?php $link1 = mysql_connect('localhost','root','',false); $link2 = mysql_connect('localhost','root','',false); echo "link1 : "; var_dump($link1); echo "link2 : "; var_dump($link2); do_something_in_mysql(); // here $link1 and $link2 are still usable to do // queries which is ok for me mysql_close($link1); // here $link2 is no more usable to do queries // which is *not* ok => the bug. echo "link1 : "; var_dump($link1); echo "link2 : "; var_dump($link2); function do_something_in_mysql () { $link3 = mysql_connect('localhost','root','',false); echo "link3 : "; var_dump($link3); // do some common queries here mysql_close($link3); } ?> Expected result: ---------------- link1 : resource(4) of type (mysql link) link2 : resource(4) of type (mysql link) link3 : resource(4) of type (mysql link) link1 : resource(4) of type (Unknown) link2 : resource(4) of type (mysql link) because $link2 has not been explicitly closed the reference count should be of 1 instead of 0 (there was 3 calls to mysql_connect and only 2 calls to mysql_close) and link2 should still be usable. Actual result: -------------- link1 : resource(4) of type (mysql link) link2 : resource(4) of type (mysql link) link3 : resource(4) of type (mysql link) link1 : resource(4) of type (Unknown) link2 : resource(4) of type (Unknown) $link2 is no longer a mysql resource and the TCP connection to the mysql server is lost although there was 3 calls to mysql_connect and only 2 explicit calls to mysql_close. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=32866&edit=1