php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14478 mutliple calls to mysql_[p]connect() with same arguments return same resourceID
Submitted: 2001-12-12 21:21 UTC Modified: 2001-12-13 12:36 UTC
From: shawn at trnsplnt dot com Assigned:
Status: Closed Package: MySQL related
PHP Version: 4.0.6 OS: FreeBSD
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: shawn at trnsplnt dot com
New email:
PHP Version: OS:

 

 [2001-12-12 21:21 UTC] shawn at trnsplnt dot com
I've noticed what appears to be a bug in the 
mysql_connect() and mysql_pconnect() (or perhaps the mysql 
client libraries): multiple calls to either function with 
identical arguments return the same resource id, preventing 
me from connecting to multiple databases on the same host, 
with the same credentials. Example:

<?php

  $conn1 = mysql_connect('host','username','pass');
  $conn2 = mysql_connect('host','username','pass');
  echo "conn1: $conn1\n";
  echo "conn2: $conn2\n";

?>

Produces:

conn1: Resource id #1
conn2: Resource id #1

If I then issue a call to mysql_select_db('foo',$conn1), 
'foo' also becomes the active database on $conn2 since the 
handles point to the same resource. Doesn't this contradict 
the idea of having separate connection handles? Or is it a 
short-coming of the client libraries?

Thanks!

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-13 00:39 UTC] mfischer@php.net
This is/was an intended behaviour. There's a new expiremental  optional parameter to mysql_connect() in CVS which allows you to force to create new resource rather than reuse existing ones, e.g.:

$con1 = mysql_connect('foo','bar','baz');
$con2 = mysql_connect('foo','bar','baz', true);

Will result in $con2 being a new resource, not the same again.

Closing.
 [2001-12-13 00:40 UTC] zak@php.net
Thank you for your report. However, please review the 
documentation before submitting a bug report - this is the 
intentional and expected behavior.

 [2001-12-13 00:42 UTC] mfischer@php.net
Not bogus :) This is a feature request and has already been done a short time ago.
 [2001-12-13 12:36 UTC] shawn at trnsplnt dot com
sorry about that... I overlooked this behavior in the docs. 
but I still think that this behavior is counter-intuitive 
since it's perfectly reasonable to want to have connections 
to multiple databases on the same host with the same 
credentials... I'll check it out from CVS and give it a 
whirl.

Thanks for looking at it so quickly, though!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Sep 17 07:01:28 2024 UTC