php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8634 problem with multiple mysql links mysql_connect mysql_close
Submitted: 2001-01-10 08:09 UTC Modified: 2001-08-12 15:25 UTC
From: AndrewL at cymatrixresearch dot com Assigned:
Status: Closed Package: MySQL related
PHP Version: 4.0.4 OS: FreeBSD 4.2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: AndrewL at cymatrixresearch dot com
New email:
PHP Version: OS:

 

 [2001-01-10 08:09 UTC] AndrewL at cymatrixresearch dot com
<HTML><BODY>
<?php
  //im sure you can figure out 
  //what you need to change to make it work on your sql server =)

   echo "<B>Open first link</B><BR>\n";
  $db = mysql_connect("10.0.0.1", "bob", "smith");
  mysql_select_db("mysql",$db); 

  echo "<BR><B>Query First link</B><BR>\n";
  $result = mysql_query("SELECT Host,Db FROM host");
  while ($data = mysql_fetch_array($result)) {
    echo $data['Host']," db ",$data['Db'],"<BR>\n";
  }

  echo "<BR><B>open second links and close and continue to use first links<BR>\n";
  echo "This time we will use the link identifiers</B><BR>\n";
  $result = mysql_query("SELECT Host FROM host",$db);

  $db2 = mysql_connect("10.0.0.1", "bob", "smith");
  mysql_select_db("mysql",$db2); 


  while ($data = mysql_fetch_array($result)) {
    $sql = "SELECT Host,Db FROM host WHERE Host = '".$data['Host']."'";
    $result2 = mysql_query($sql,$db2);
    $data2 = mysql_fetch_array($result2);
    echo $data2['Host']," db ",$data2['Db'],"<BR>\n";
  }
  mysql_close($db2);

  echo "<BR><B>back to the first link or what *SHOULD* be the first link but errors happen.</B><BR>\n";
  $result = mysql_query("SELECT Host,Db FROM host");
  while ($data = mysql_fetch_array($result)) {
    echo $data['Host']," db ",$data['Db'],"<BR>\n";
  }

 echo "<BR><B>And finaly use the first link identifier and it works</B><BR>\n";
  $result = mysql_query("SELECT Host,Db FROM host",$db);
  while ($data = mysql_fetch_array($result)) {
    echo $data['Host']," db ",$data['Db'],"<BR>\n";
  }

?>
<BR><B>Final note: This worked just fine before I upgraded from aprox 4.0.3p12 or something.
 I was able to call mysql_query after a mysql_close on a second link the switching back to
 the first link happend automaticly.</B><BR>
</BODY></HTML>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-05-30 22:26 UTC] sniper@php.net
Reproduced under PHP 4.0.6RC1
Marked as fix before release.

--Jani

 [2001-08-12 15:25 UTC] sebastian@php.net
fixed in 4.0.6
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 08:01:27 2025 UTC