문제

I'm trying to copy some data between different databases. For testing i used simply two databases both on localhost and everything worked fine but as soon as I try to establish the connection to two different hosts it doesn't work anymore. My code looks like this:

$sourceDb = new ezSQL_mysql($settings['dbuser'], $settings['dbpass'], $settings['dbname'], $settings['dbhost']);

$targetDb = new ezSQL_mysql($settings['syncdbuser'], $settings['syncdbpass'], $settings['syncdbname'], $settings['syncdbhost']);

And the error message is this:

Warning: Error establishing mySQL database connection.
Correct user/password? Correct hostname?
Database server running? in ez_sql_mysql.php on line 89
PHP Warning:  mySQL database connection is not active
 in ez_sql_mysql.php on line 121

Is there any problem I'm not aware of, that prevents two connections to different hosts?

Btw. the connection information is 100% correct.. if I only use one connection everything works without any problems!

도움이 되었습니까?

해결책

I still don't know why I got this error. Switched to PDO and have no problems..

다른 팁

This solution is for 3.08 version.

The problem is caused by the connect function. The Function get database name from constract . If variable is determined first time, it will not work for second or more.

Fistly; please open /lib folder

  • Choose the file according to your database ( etc. ez_sql_mysqli.php )

  • find function connect( ....

  • change it public function connect($dbuser='', $dbpassword='', $dbhost='localhost', $charset='') to public function connect($dbuser='', $dbpassword='', $dbhost='localhost', $charset='', $dbname='')

  • find $this->_dbname inside function (connect). change it to $dbname. ( you can put " if($dbname==""){ $dbname=$this->_dbname; } " before $dbname )

  • find quick_connect inside class; change $this->connect($dbuser, $dbpassword, $dbhost, true) to $this->connect($dbuser, $dbpassword, $dbhost, true, $dname)

  • it will work.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top