how to work with a remote mysql database ??

altariamx2003 used Ask the Experts™
I got two servers: "" with linux and "" with windows

in the page load his own database but also the mysql databse located in "", most of the time the system works without problems, but from time to time the page show you this error:
Warning: mysql_connect(): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\Inetpub\vhosts\\httpdocs\users\Connections\dbnotes1.php on line 16

Fatal error: in C:\Inetpub\vhosts\\httpdocs\users\Connections\dbnotes1.php on line 16

Open in new window

that error reffers to this line:
$dbnotes1 = mysql_connect($hostname1, $username1, $password1) or trigger_error(mysql_error(),E_USER_ERROR);
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_dbnotes = "localhost";
$database_dbnotes = "xxxxxx";
$username_dbnotes = "xxxxxx";
$password_dbnotes = "xxxxxx";
$dbnotes = mysql_connect($hostname_dbnotes, $username_dbnotes, $password_dbnotes) or trigger_error(mysql_error(),E_USER_ERROR); 

$hostname1 = "";
$database1 = "xxxxxx";
$username1 = "xxxxxx";
$password1 = "xxxxxx";
$dbnotes1 = mysql_connect($hostname1, $username1, $password1) or trigger_error(mysql_error(),E_USER_ERROR);

Open in new window

Anyone know why this error happend but just sometimes??? and it is  a way to solve it??????
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
John TsioumprisSoftware & Systems Engineer

Are you sure the server  with Linux works correctly...have checked if this is an network connectivity logging for MySQL working?


hi john thx for your time.

As far as i know all work ok, this problems sometimes emerges when i try to connect the base in from
John TsioumprisSoftware & Systems Engineer

The "sometimes" points to something between pvtcloudlab and grupossc...i don't think its MySQL's ensure that there are several stress test floating on the Internet...
Most Valuable Expert 2011
Top Expert 2016
There are two issues here.  First, the timeout.  It almost does not matter what might be causing this - internet traffic, server load, etc.  This should not be handled as a fatal error.  Your script should sleep() for one second and retry.  Downgrade the error level to E_USER_WARNING, suppress error display, and just log the error.  Maybe tweet or email to the server admin at the balky server.  HTTP(S) delays are common, and treating them as fatal errors is overkill.  I would retry up to 10 times, for starters.

Second, you're obviously using an out-of-date script.  The MySQL extension is not supported any more, and it has been removed from all current levels of PHP, so it's time to upgrade.  You should be up to PHP 7.1 and you need to get off MySQL.  Instead of MySQL choose one of the extensions that still exists: MySQLi or PDO.  Here is how and why that is necessary:

A substantial benefit of upgrading your PHP will be visible when you start to compare performance.  PHP 7+ is often twice as fast as the old versions!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial