Page 1 of 1

mysql_connect and timeout

Posted: Sat Nov 07, 2009 8:17 am
by webstyler
Hello

I have a connection to mysql as

$ndb = mysql_connect($host,$dbuser,$dbpass, TRUE) or die ("Database Connection Error<br>");

There are many php function tah can be take many time, so after this I check if connection is live with

if (!$ndb)
..
reconect code
..

Problem is that $ndb is always TRUE also when is timeout (by wait_timeout on my.cnf)

So, how check if connection is live and not timeout ?

Thanks

Re: mysql_connect and timeout

Posted: Sat Nov 07, 2009 9:21 am
by Apollo
Once you have done $ndb = mysql_connect(...), later on $ndb won't suddenly change by itself if you get disconnected.

You can try mysql_ping, or alternatively try connecting with mysql_pconnect instead of mysql_connect.

Re: mysql_connect and timeout

Posted: Sat Nov 07, 2009 10:26 am
by webstyler
Apollo wrote:Once you have done $ndb = mysql_connect(...), later on $ndb won't suddenly change by itself if you get disconnected.

You can try mysql_ping, or alternatively try connecting with mysql_pconnect instead of mysql_connect.
Hi

mysql_ping() seems the work way :)

thanks