我在不同的主机中有 2 个连接数据库(MySQL),如下所示:
//database 1
$dbhost='localhost';
$dbuser='user1';
$dbpass='pass1';
$dbname='dbname1';
//database 2
$dbhostams='192.168.16.3';
$dbuserams='user2';
$dbpassams='pass2';
$dbnameams='dbname2';
function dbconnection($dbhost,$dbuser,$dbpass,$dbname){
if(!mysql_connect($dbhost,$dbuser,$dbpass)){
echo "Error occure on opening connection or database. Period.";
}else{
if(!mysql_select_db($dbname)){
echo "Error occure on select databases !";
}
}
}
function dbconnectionams($dbhostams,$dbuserams,$dbpassams,$dbnameams){
$cxn = mysql_connect($dbhostams,$dbuserams,$dbpassams,$dbnameams);
if( $cxn === FALSE ) {
die('mysql connection error: '.mysql_error());
}else{
if( !mysql_select_db($dbnameams) ){
echo "Error occure on select databases !";
}
}
}
当我使用:
dbconnection($dbhost,$dbuser,$dbpass,$dbname);
在我的页面代码中,并使用:
dbconnectionams($dbhostams,$dbuserams,$dbpassams,$dbnameams);
在同一页面的另一行代码中,发生错误,如下所示:
警告:用户访问被拒绝:'apache@localhost'(使用密码:否) /home/firman/html/fdrsimpeg/sdm-aam/include/dbclass.php 在第 17 行 警告:MySQL 连接失败:用户访问被拒绝:'apache@localhost' (使用密码:否)在 /home/firman/html/fdrsimpeg/sdm-aam/include/dbclass.php 在第 17 行 mysql连接错误:
我必须怎么做才能解决这个问题?