mysql_connect and timeout

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
webstyler
Forum Commoner
Posts: 85
Joined: Sat Feb 14, 2004 2:16 am

mysql_connect and timeout

Post 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
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: mysql_connect and timeout

Post 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.
webstyler
Forum Commoner
Posts: 85
Joined: Sat Feb 14, 2004 2:16 am

Re: mysql_connect and timeout

Post 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
Post Reply