| Bug #30525 | mysql_close() fails in some situations with shared links | ||||
|---|---|---|---|---|---|
| Submitted: | 22 Oct 2004 6:19am UTC | Modified: | 29 Apr 2005 3:39am UTC | ||
| From: | l dot cameron2 at ugrad dot unimelb dot edu dot au | Assigned to: | |||
| Status: | Bogus | Category: | MySQL related | ||
| Version: | 5.0.x and 4.x | OS: | * | ||
| Votes: | 4 | Avg. Score: | 4.5 ± 0.9 | Reproduced: | 3 of 3 (100.0%) |
| Same Version: | 0 (0.0%) | Same OS: | 1 (33.3%) | ||
[22 Oct 2004 6:19am UTC] l dot cameron2 at ugrad dot unimelb dot edu dot au
[27 Apr 2005 1:25pm UTC] kevin at hatry dot com
i just want to add a last comment to make clear that this bug is
important.
this is (i think) a much used type of program :
<?php
function do_something_in_mysql () {
$link3 = mysql_connect('localhost','root','',false);
// do some common queries here
mysql_close($link3);
echo "link3:"; var_dump($link3);
}
$link1 = mysql_connect('localhost','root','',false);
echo "link1:"; var_dump($link1);
do_something_in_mysql();
// here $link1 is UNUSABLE !!
mysql_close($link1);
echo "link1:"; var_dump($link1);
?>
fails with :
link1:resource(4) of type (mysql link)
link3:resource(4) of type (mysql link)
Warning: mysql_close(): 4 is not a valid MySQL-Link resource in ... on
line 14
link1:resource(4) of type (Unknown)
i think that closing a connection in the same environnement that it was
open (like in the function here) is good programming so it shouldn't
fail like that !
And the problem is *not* that the mysql_close closed all connections as
shown by this example :
<?php
function do_something_in_mysql () {
$link3 = mysql_connect('localhost','root','',false);
echo "link3:"; var_dump($link3);
// do some common queries here
mysql_close($link3);
}
$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 is still USABLE
mysql_close($link1);
echo "link1:"; var_dump($link1);
echo "link2:"; var_dump($link2);
?>
here there is no failure :
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)
there would be one if we had closed $link2 after $link1 for example.
[27 Apr 2005 2:48pm UTC] georg@php.net
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php When using same connection parameters no new connection will be established by default, instead an exisiting one will be reused. Set the optional newlink parameter to true if you want to establish more than one physical connection.
[29 Apr 2005 1:56am UTC] l dot cameron2 at ugrad dot unimelb dot edu dot au
Please reread the first post where I explicitly talked about shared connection behaviour. The bug is that when using shared connections, if you ever use mysql_close() *and* set your links to null, your shared connections will be closed prematurely. As outlined above, the net result of the is that you can never call mysql_close() on a shared connection and expect to have it work correctly.
[29 Apr 2005 3:39am UTC] sniper@php.net
Please stop reopening this, this is not a bug but just how it works.
