note 56166 added to ref.mysql
| From: | dot) | Date: | Thu, 25 Aug 2005 14:23:00 +0000 |
| Subject: | note 56166 added to ref.mysql | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94184@lists.php.net to get a copy of this message | ||
A note on resources
When a resource (e.g. a link identifier) runs out of scope, it is deleted and the associated
computer resources (e.g. the tcp link to the database) will be terminated as well. So far so good!
However, in the following code the tcp mysql link persists until the end of execution:
<?php
$conn = mysql_connect('hostname', 'username','password');
$conn = null;
sleep (30);
?>
This is because the internally the link-identifier is being saved, so that subsequent mysql
functions will work. There seems to be no way to delete this internal reference.
If you were, however, to open 2 connections, the oldest one will be deleted automatically (so the
connection to hostname will terminate at the $conn=null statement, the connection to hostname2 will
exist till the end of the script).
<?php
$conn = mysql_connect('hostname', 'username','password');
$conn2 = mysql_connect('hostname2', 'username','password');
$conn = null;
$conn2 = null;
sleep (30);
?>
----
Manual Page -- http://www.php.net/manual/en/ref.mysql.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56166
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56166&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56166&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56166&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56166&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56166&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56166&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56166&report=yes
Search -- http://master.php.net/manage/user-notes.php