mysql problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
valen53
Forum Contributor
Posts: 137
Joined: Tue Aug 27, 2002 9:29 am

mysql problem

Post 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
User avatar
cactus
Forum Regular
Posts: 343
Joined: Tue Jun 10, 2003 4:16 am
Location: UK

Post 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,
valen53
Forum Contributor
Posts: 137
Joined: Tue Aug 27, 2002 9:29 am

Post 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 ?
User avatar
delorian
Forum Contributor
Posts: 223
Joined: Sun May 04, 2003 5:20 pm
Location: Olsztyn, Poland

Post 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.
User avatar
cactus
Forum Regular
Posts: 343
Joined: Tue Jun 10, 2003 4:16 am
Location: UK

Post 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") 
}
User avatar
delorian
Forum Contributor
Posts: 223
Joined: Sun May 04, 2003 5:20 pm
Location: Olsztyn, Poland

Post by delorian »

oh, I'm sorry :D But, hmmm, it doesn't do much, if $base_handler is not set at the first it won't be set at second try.
User avatar
cactus
Forum Regular
Posts: 343
Joined: Tue Jun 10, 2003 4:16 am
Location: UK

Post 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.
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post 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");
}
:)
User avatar
cactus
Forum Regular
Posts: 343
Joined: Tue Jun 10, 2003 4:16 am
Location: UK

Post by cactus »

Perfection. :D
Post Reply