#21663 [Opn->Bgs]: Functions closing mysql resources
| From: | georg@php.net | Date: | Wed, 15 Jan 2003 17:33:13 +0000 |
| Subject: | #21663 [Opn->Bgs]: Functions closing mysql resources | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-30136@lists.php.net to get a copy of this message | ||
ID: 21663
Updated by: georg@php.net
Reported By: darylm@magiasoftware.com
-Status: Open
+Status: Bogus
Bug Type: MySQL related
Operating System: Unix (FreeBSD)
PHP Version: 4.2.3
New Comment:
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
See http://www.php.net/manual/en/function.mysql-connect.php
Previous Comments:
------------------------------------------------------------------------
[2003-01-15 10:15:22] darylm@magiasoftware.com
There are two databases involved:
database1 is connected to in the main body of the page
database2 is connected to in a function
========================================================
function foo()
{
mysql_connect(Same Arguements)
db1_connection = select_db (db1)
do something
close db1_connection
}
mysql_connect(Same Arguements)
db2_connection = select_db(db2)
do something with db1
foo()
do something with db1 //**** This will fail
======================================================
The second "do something with db1 will fail with a "not a valid result
resource" error. I percieve of two possible reasons for this:
1. mysql_close(db1_connection) is closing all the links
or, most likely
2. Since mysql_connect is called with the same arguements it returns
the same resource id (I know this) then, when I close db1_connection it
closes that resource.
So, either way we have a variable scope issue. According to what I
understand about the scope rules of php the functions should have no
knowledge of my connection to db2 unless I declare it as global in the
function foo. But, it does anyway.
As an aside, I used to be able to globally include a resource id into a
function, leave it open and return from the function. Now, it appears
that when the function exits it disposes of the "global" resource in
its clean up proceedures.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=21663&edit=1