2013-05-17 31 views

回答

2

您可以對mysql_connect()進行多次調用,但如果參數相同,則需要爲「$ new_link」(第四個)參數傳遞true,否則將重用相同的連接。

,那麼你有

$dbh1 = mysql_connect($hostname, $username, $password); 
$dbh2 = mysql_connect($hostname, $username, $password, true); 


mysql_select_db('database1', $dbh1); 
mysql_select_db('database2', $dbh2); 

然後查詢數據庫1,這樣做:

mysql_query('select * from tablename', $dbh1); 

和數據庫2:

mysql_query('select * from tablename', $dbh2); 
+2

你真的不應該推薦使用mysql_ *函數。 http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – thpl

+0

我知道,這只是我仍然需要習慣它,這只是一個例子。 – Matheno