Use of Resource link_identifier in mysql_query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Use of Resource link_identifier in mysql_query

Post by anjanesh »

I have two diferent connections :

$Con1=mysql_connect($IP1,$Username1,$Password1);
$Con2=mysql_connect($IP2,$Username2,$Password2);

mysql_select_db($db1,$Con1);
mysql_select_db($db2,$Con2);

This what I tried to do:

$Res1=mysql_query($sql1,$Con1);
$Res2=mysql_query($sql2,$Con2);

All this time I coudn't figure out why it was failing then I found out that I need to select the db again when switching connections :

mysql_select_db($db1,$Con1);$Res1=mysql_query($sql1,$Con1);
mysql_select_db($db2,$Con2);$Res2=mysql_query($sql2,$Con2);

Then only it would work alright. Then whats the point of having the optional resource link_identifier argument in mysql_query() if we need to select_db each time ?

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you could try using [php_man]mysql_db_query[/php_man]() :)
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

mysql_db_query ( string database, string query [, resource link_identifier])
is the same as
mysql_select_db() and then mysql_query()

I was hoping resource link_identifier would be having a unique id for each connection and select the db automatically.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it looks like mysql_select_db sets a session-wide database to use instead of a connection hook. So you may want to look at the bug database about it.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Alright
Thanks
Post Reply