MYSQL多库联合查询

1.给要用到的每个库都建立一个连接;
2.中间不要断开连接(如mysql_close($conn)).

代码如下:

php
$dbconn1 = mysql_connect("localhost","root","admin888") or die("db1 error");
$db1 = mysql_select_db("db",$dbconn1) or die ("db1 select error");
$dbconn2 = mysql_connect("localhost","root","admin888") or die("db2 error");
$db2 = mysql_select_db("mydb",$dbconn2) or die("db2 select error");

$res = mysql_query("select * from db.t3 t join mydb.goods g on t.id=g.gid");
while($row = mysql_fetch_assoc($res)){
    var_dump($row);
}
?>

 

转载于:https://www.cnblogs.com/thinksasa/archive/2013/06/08/3126897.html

你可能感兴趣的:(MYSQL多库联合查询)