PHP同时操作多个MySQL连接

不能连接数据库!");
mysql_select_db('gameupload',$con_1);
$con_2 = mysql_connect('localhost','root','')or die("不能连接数据库!");
mysql_select_db('blog4',$con_2);
$sql = "select * from user limit 2";
$res = mysql_query($sql,$con_1);
echo mysql_error();
while($row = mysql_fetch_assoc($res)){
	print_r($row);
}
?>


运行结果:只显示gameupload里的user内容。

-------------------------------

不能连接数据库!");
mysql_select_db('gameupload',$con_1);
$con_2 = mysql_connect('127.0.0.1','root','')or die("不能连接数据库!");
mysql_select_db('blog4',$con_2);
$sql = "select * from user limit 2";
$res = mysql_query($sql,$con_1);
echo mysql_error();
while($row = mysql_fetch_assoc($res)){
	print_r($row);
}
?>

运行结果:显示blog4里的user内容。

------------------

参考来源:http://blog.csdn.net/iamtrooper/article/details/4139209

你可能感兴趣的:(php)