PHP同时连接多个mysql数据库示例代码
在mysql_query函数中指定所用连接,即:
<?php
$conn1 = mysql_connect("127.0.0.1", "root","root","db1");mysql_select_db("Muma", $conn1);
$conn2 = mysql_connect("127.0.0.1", "root","root","db2");
mysql_select_db("product", $conn2);
$sql = "select * from ip";
$query = mysql_query($sql,$conn1); //添加连接$conn1
if($row = mysql_fetch_array($query))
echo $row[0]."\n";
$sql = "select * from web ";
$query = mysql_query($sql, $conn2);
if($row = mysql_fetch_array($query))
echo $row[0];
?>
版权声明:若无特殊注明,本文皆为《菜鸟站长》原创,转载请保留文章出处。
本文链接:PHP同时连接多个mysql数据库示例代码 - https://wziyi.com.cn/?post=72