Jump to content

Why Do I Keep Getting This Error?


Nathan Johnson

Recommended Posts

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?

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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. ;)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...