Multiple MySQL Connections

php.internals

Nick Mitin

20 years ago
I was trying to create 2 mysql connections. $l1 = mysql_pconnect(“localhost”, “user”, “pass”); mysql_select_db(“db1”, $l1); $l2 = mysql_pconnect(“localhost”, “user”, “pass”); mysql_select_db(“db1”, $l2); The $l1 and $l2 now contains different resource ids (#1, #2), but mysql_query(“select * from table”, $l1) somehow uses the second connection. If I change the username in second connection to user1 (assuming user1 as valid login) $l2 = mysql_pconnect(“localhost”, “user1”, “pass”); mysql_select_db(“db1”, $l2); everything is fine. I found this pretty strange. ________________________________________ Nick Mitin Borzov-Mitin Solutions, The // http://tbms.ru

Lukas Smith

20 years ago
Nick Mitin wrote:
> I was trying to create 2 mysql connections.
this is a user question and should therefore not be directed at the internals list.. 1) persistent connections have issues: http://de2.php.net/manual/en/features.persistent-connections.php 2) use the new link parameter to get a new connection for a host you previously already connected to: http://de2.php.net/manual/en/function.mysql-connect.php regards, Lukas

Antony Dovgal

20 years ago
On 13.03.2006 18:05, Nick Mitin wrote:
> I was trying to create 2 mysql connections. > > $l1 = mysql_pconnect(“localhost”, “user”, “pass”); > mysql_select_db(“db1”, $l1); > > $l2 = mysql_pconnect(“localhost”, “user”, “pass”); > mysql_select_db(“db1”, $l2); > > The $l1 and $l2 now contains different resource ids (#1, #2), but > > mysql_query(“select * from table”, $l1) somehow uses the second connection.
Yes, this is the same connection. This is by design. If you need to open a separate connection - use mysql_connect() with 4th parameter set to TRUE.
-- Wbr, Antony Dovgal