php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9497 closed mysql connection after calling a function that uses another mysql conn.
Submitted: 2001-02-28 08:55 UTC Modified: 2001-03-03 20:01 UTC
From: coberau at gmx dot net Assigned:
Status: Closed Package: MySQL related
PHP Version: 4.0.4 OS: SuSE Linux 7.0
Private report: No CVE-ID: None
 [2001-02-28 08:55 UTC] coberau at gmx dot net
in file functions.inc:

function func1($blabla) {
   $conn = mysql_connect ("host","user","pass");
   mysql_select_db("db",$conn);
   $resset=mysql_query("SELECT a,b,c FROM ATable",$conn);
   mysql_close($conn); 
}

-------------------

file index.php:
include ("functions.inc");

$conn_main = mysql_connect ("host","user","pass");
mysql_select_db("db",$conn_main);

$resset=mysql_query("SELECT a,b,c FROM ATable",$conn_main); <-- this statement works and returns a result
func1($abc); <-- call defined function
$resset=mysql_query("SELECT a,b,c FROM ATable",$conn_main); <-- after calling the above defined function i get an error: warning: 1 is not a valid mysql link resource

mysql_close($conn_main); 

so thats the problem:
i have a script that makes a mysql connection. i can select, update, insert aso. from the db. then i call a function that itself makes a connection to the same db, does something with it (works fine) closes the connection and returns. i dont use global or give the main connection as an argument, its just a plain standalone function. after calling the function the main script has lost its mysql connection (its no timeout since the function doesnt take long to execute).

the same scripts work with PHP version 4.0.1pl2. both pcs have the same setup (apache 1.3.12, mysql 3.22.32, the rest as rpms from the distibution cds). its all the same except the php-version (both compiled with the standard options --with-apxs --with-mysql -> make -> make install)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-03 20:01 UTC] sniper@php.net
From NEWS file:
------------------------------------------------------
- Fixed mysql_close(), pg_close(), msql_close() and sybase_close() - they
  weren't properly closing the SQL connections (Zeev)
------------------------------------------------------

Read also the manual page for mysql_connect() :

http://www.php.net/mysql_connect

Where it says:

"If a second call is made to mysql_connect() with the same arguments, no new link 
will be established, but instead, the link identifier of the already opened link will be 
returned. "

ie. You relied on buggy behaviour of mysql_close() function.

--Jani

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 30 04:01:30 2024 UTC