A strange question about mysql_close()
| From: | 唐家兴 | Date: | Thu, 17 Dec 2009 03:58:51 +0000 |
| Subject: | A strange question about mysql_close() | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-300555@lists.php.net to get a copy of this message | ||
I want to ask a strange question.
As we know, if we connect a mysql database in the same host twice with the
same username, we won't get two new link, but two handle to only one link.
Then, if I close one of them, whether the other one will be closed together?
I wrote two pieces of code. The first is like this
<?php
$db1 = mysql_connect($host, $username, $pwd);
$db2 = mysql_connect($host, $username, $pwd);
$sql = 'show databases';
mysql_close($db1);
$res = mysql_query($sql, $db2);
$a = mysql_fetch_row($res);
print_r($a);
?>
Then the output of the $db2 is correct. So the $db2 isn't closed together
with the $db1.
But when I add a line among the code, the result is different
<?php
$db1 = mysql_connect($host, $username, $pwd);
$db2 = mysql_connect($host, $username, $pwd);
$sql = 'show databases';
mysql_close($db1);
$db1 = true; //a new line
$res = mysql_query($sql, $db2);
$a = mysql_fetch_row($res);
print_r($a);
?>
Then the output is wrong. The PHP tell me that the link is not a valid one.
I don't know how an assignment operation for the $db1 can close the $db2.
Could someone help me.
I'll appreciate your help.