Jump to content

Recommended Posts

Posted

Hi

 

I keep getting this error:

 

 

It used to never do this. What could be happening? This is the code of 'connection.php':

 

 

<?php
$username = "username_here";
$password = "password_here";
$con = mysql_connect("localhost",$username,$password);
if (!$con)
 {
 die('<br /><br /><strong style="font-family: arial;">Could not connect to the database: ' . mysql_error() . '</strong>');
 }
?>

 

Am I doing something wrong?

Posted

I'm not seeing that error right now.

 

Yeah, it isn't right away. It only happens after I click around and stuff.

Posted

This is probably stating the obvious, but sometimes we overlook these things.

 

Could it be that you're not closing connections after use?

They may be accumulating if many connections are established within a short amount of time. Some sort of loop elsewhere which skips a closure may also be responsible for this.

 

I don't know the settings on Stevie, but max_conn on Johnny is 30 and i'd expect much of the same there, it wouldn't take much clicking through pages to exceed that limit, especially if there's more than 1 active user at this stage.

 

Just a thought...

 

I've heard that closing MySQL connections isn't required. They automatically close at the end of the page. But, I'll try closing all them manually with mysql_close(). Thanks :)

 

It is odd that it wasn't happening before, though...

Posted

I close them all the time, as early as possible. I wasn't aware of any auto-closing at end of page (there might well be, I've never really given it any thought or read up on it). However if it frees up a connection slot a few milliseconds earlier on a shared server, being wrong dosen't do any harm. ;)

Posted

I close them all the time, as early as possible. I wasn't aware of any auto-closing at end of page (there might well be, I've never really given it any thought or read up on it). However if it frees up a connection slot a few milliseconds earlier on a shared server, being wrong dosen't do any harm. ;)

 

Yeah, I'm gonna start closing them. They do close by themselves at the end of the page, but I think closing them sooner would be much better as it is only getting some info from the database, putting the info into variables, and that's it, so closing it after would be better, because if it closes it at the end, it is a longer-open connection.

 

Also, the manual says:

 

Using mysql_close() isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution.

 

But, once again, closing it before the end of the page is probably better.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...