<?php $con_1 = mysql_connect('localhost','root','')or die("<font color=red>不能连接数据库!</font>"); mysql_select_db('gameupload',$con_1); $con_2 = mysql_connect('localhost','root','')or die("<font color=red>不能连接数据库!</font>"); 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内容。
-------------------------------
<?php $con_1 = mysql_connect('localhost','root','')or die("<font color=red>不能连接数据库!</font>"); mysql_select_db('gameupload',$con_1); $con_2 = mysql_connect('127.0.0.1','root','')or die("<font color=red>不能连接数据库!</font>"); 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