php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #14137 Request additional flag for mysql_connect
Submitted: 2001-11-20 04:17 UTC Modified: 2001-11-22 03:26 UTC
From: lenar at vision dot ee Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0CVS-2001-11-20 OS: Debian/Linux
Private report: No CVE-ID: None
 [2001-11-20 04:17 UTC] lenar at vision dot ee
Manual states:

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. 

Most of the times this is good. With one exception.

Let's describe this situation.
I have 2 databases. I have 1 user account for mysql.
I need to use both of those databases simultaneously in my
script.
Now i do:
$id1 = mysql_connect($host, $username, $password);
mysql_select_db("db1", $id1);
$id2 = mysql_connect($host, $username, $password);
mysql_select_db("db2", $id2);

And now I think why so many errors :(

Second call to mysql_connect() returns same resource, so 
my active database is db2 now. But I want to use data from 
two databases at once. So this 'reuse' feature is bad for 
me.

Now, I use a wrapper class so I could issue an 
mysql_select_db() every time I do a query. But I think 
this is not a wise thing to do.

So I ask: Shouldn't be there a flag with meaning like 'do 
not try to reuse exitsing connection'. Or may be just an 
additional string argument 'database' which when specified
automagically selects that database and subsequent calls to
mysql_connect() take that value into account when deciding
to return or not to return existing resource.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-11-20 12:34 UTC] bate@php.net
bool mysql_select_db (string database_name, resource [link_identifier])

http://www.php.net/manual/en/function.mysql-select-db.php


--Marco


P.S. Maybe you upgrade your system or you learn to read the manual pages.
 [2001-11-20 12:48 UTC] bate@php.net
Ups sorry wrong links. :)

http://www.php.net/manual/en/ref.mysql.php
http://www.php.net/manual/en/function.mysql-db-query.php

--Marco


Note: This function has been deprecated since PHP 4.0.6. Do not use this function. Use mysql_select_db() and mysql_query() instead. 

read the User comment's

 [2001-11-20 12:57 UTC] mfischer@php.net
Not so fast ..

This is definitely a problem when you try to connect to MySQL twice with the same incredentials (host,user,pass) you don't get the old link back and thus changing the database on one link obviously changes it on the other too ...

Should be a Feature Request, note sure.

A workaround is to create another user.

Reopened.
 [2001-11-20 12:57 UTC] mfischer@php.net
Mistake, should read "...you get the old link back..."
 [2001-11-20 13:00 UTC] derick@php.net
Marko, will you please read the bugreport with more care the next time? THis is a valid report, but moving it to a feature request.

Derick
 [2001-11-20 15:01 UTC] lenar at vision dot ee
I just want to add that creating another mysql account
is not an valid option sometimes (with hosting companies 
for example). Although yes, this will solve the problem.


 [2001-11-22 03:26 UTC] mfischer@php.net
Fixed in CVS.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 06 09:01:26 2024 UTC