phpmysql-select-db

php mysql_select_db parameter 2 not working


I have the following code for test, and I just found the 2nd parameter is not actually working.

$conn1 = mysql_connect("127.0.0.1", "xxxx", "xxxx");
$conn2 = mysql_connect("127.0.0.1", "xxxx", "xxxx");

mysql_select_db("test", $conn1);
mysql_select_db("yangshengfun", $conn2);

if (!$res = mysql_query("select * from proxy_ips limit 1", $conn1)) {
    echo mysql_error($conn1);
}


if (!$res = mysql_query("select * from wp_posts limit 1", $conn2)) {
    echo mysql_error($conn2);

The tables in database 'test' and 'yangshengfun' are complately different. An error occured while I run this code:

Table 'yangshengfun.proxy_ips' doesn't exist

Seems when I call mysql_select_db for $conn2, it changes the current db of $conn1 too, any ideas?


Solution

  • try this

     $conn1= mysql_connect("host_name", "user_name", "pass_word") or die('not connected'); 
     mysql_select_db("database_name", $conn1);
    

    Here the "die($message)" function prints a message if mysql_connect() function can't connect with db.