How to connect multiple MySQL databases in PHP
Sometimes, we may be in a PHP project to connect multiple MySQL database, it is necessary to write multiple mysql_connect and mysql_select_db, but some children's shoes found written to write all in fact always call the last database.
In fact, the correct wording is:
Database 1
$conn 1 = mysql_connect (' localhost:3306 ', ' root ', ' 111111 ', true);
mysql_select_db (' db1 ', $conn 1);
mysql_query (' Set names UTF8 ');
Database 2
$conn 2 = mysql_connect (' localhost:3306 ', ' root ', ' 222222 ', true);
mysql_select_db (' DB2 ', $conn 2);
mysql_query (' Set names UTF8 ');
The principle is that the Mysql_connect function sets the "New_link" parameter to true to force the use of the new connection.
mysql_connect function
Resource mysql_connect ([string server [, String username [, string password [, bool new_link [, int client_flags]]])
http://www.bkjia.com/PHPjc/834968.html www.bkjia.com true http://www.bkjia.com/PHPjc/834968.html techarticle ways to connect multiple MySQL databases in PHP Sometimes, we might connect multiple MySQL databases in a PHP project, write multiple mysql_connect and mysql_select_db, but some kids ...