如何使用php和mysql同时连接不同主机上的两个数据库?

时间:2015-01-13 06:30:57

标签: php html mysql arrays database-connection

$connection1 = mysql_connect($servername,$username,$password);
$db1 = mysql_select_db($dbname,$connection1);

some html and php code here

$connection2 = mysql_connect($servername1,$username1,$password1);    
$db2 = mysql_select_db($dbname1,$connection2);

错误:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user '*****'@'***.com' (using password: YES) in /home/

Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in /home/

Warning: mysql_query() [function.mysql-query]: Access denied for user '******'@'********' (using password: NO) in /home/

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/

当我想要获取某些内容或尝试连接时,我收到此错误

1 个答案:

答案 0 :(得分:0)

您必须在主机cpanel上添加IP地址,方法是删除MySQL以允许远程访问。