同一个PHP页面连接两个数据库
程序员文章站
2024-03-21 19:46:40
...
<?php
/**
* @author blog.anchen8.net
* @copyright 2016
*/
$conn1 = mysql_connect("127.0.0.1", "root", "123456");
mysql_select_db("newwww", $conn1);
$conn2 = mysql_connect("127.0.0.1", "root", "123456");
mysql_select_db("weixin", $conn2);
$sql = "select nickname from newwww.zg_user";
$query = mysql_query($sql) or die(mysql_error()); //添加连接$conn1
if($query){
while($row = mysql_fetch_array($query)) {
echo $row[0]."\n";
break;
}
}else{
echo "conn1,else";
}
$sql = "select * from weixin.member ";
$query = mysql_query($sql) or die(mysql_error());
if($query){
while($row = mysql_fetch_array($query)) {
echo $row[0]."\n";
break;
}
}else{
echo "conn2,else";
}
mysql_close($conn1);
mysql_close($conn2);
?>
上一篇: 约瑟夫循环问题