Page 1 of 1
mysql problem
Posted: Tue Jun 10, 2003 8:49 pm
by valen53
i got a question.
in wht kind of situation, mysql will lost connection ?
b'cos sometime i will lost connection , when data occurs error or duplicate.
anyone can give me comment?
thank u
Posted: Wed Jun 11, 2003 2:13 am
by cactus
Network traffic.
Reached max number of connections.
Fix by checking if you are returned a handler from the mysql_pconnect() (or mysql_connect) method, if you don't have one try again.
Regards,
Posted: Wed Jun 11, 2003 8:37 pm
by valen53
Fix by checking if you are returned a handler from the mysql_pconnect() (or mysql_connect) method
thank ur reply
actually i dunno wht u mean about the above word. and how to checking and fix ?
Posted: Thu Jun 12, 2003 5:03 am
by delorian
First off all try not to use mysql_pconnect(). It should use the connection which is open but sometimes it did not, so after a while you recieve a over-connection-error

. It's better to use mysql_connect() to set a connection and mysql_close() to close it.
Secondly the user cactus tried to say that you must check if the script made the connection with the database or not, something like this:
Code: Select all
$base_handler = mysql_connect("localhost","login","pass") or die("You didn't connect to the database."):
But of course I don't know if that's the thing you are up to. Please write some more details about the problem.
Posted: Thu Jun 12, 2003 5:09 am
by cactus
Actually I meant:
Code: Select all
$base_handler = mysql_connect("localhost","login","pass")
if(!isset($base_handler))
{
$base_handler = mysql_connect("localhost","login","pass")
}
Posted: Thu Jun 12, 2003 5:16 am
by delorian
oh, I'm sorry

But, hmmm, it doesn't do much, if $base_handler is not set at the first it won't be set at second try.
Posted: Thu Jun 12, 2003 5:21 am
by cactus
Can you guarntee that ?? There may be too many connections on the dB already (max connections reached), or increased network traffic that impeades the connection and as a result Apache may timeout waiting for a response fom the dB.
While you may have a setup that stops the processing of a PHP page on every error, most prodcution systems will try and fail gracefully.
Having another go before you die() is a better option that just expecting the second try to fail.
Posted: Thu Jun 12, 2003 5:24 am
by []InTeR[]
Code: Select all
$base_handler = @mysql_connect("localhost","login","pass");
while(!isset($base_handler))
{
sleep(1);
$base_handler = @mysql_connect("localhost","login","pass");
}

Posted: Thu Jun 12, 2003 5:27 am
by cactus
Perfection.
