Jump to content
MakeWebGames

MYSQL.PHP


MobTown

Recommended Posts

Recently I have purchased version 1 (yeah i'm cheap)

of MCCodes, i have had no problems up until the last few days, in those few days i keep getting the message

 

Warning: mysql_connect() [function.mysql-connect]: Too many connections in /home/www/lords-of-mobtown.com/mysql.php on line 3

I got onto my host, as i believed that is where the fault lied, however they have told me it is probably due to not closing the sql connection.

Could some please adivise me if this is indeed the problem, my mysql.php file can be seen below, (naturally i have * sensitive data)

 

<?

$c=mysql_connect('***.***.com','******_******','password') or die('Sorry, technical faults have slowed down this site, please try again later.');

mysql_select_db('*****_****',$c);

?>

Link to comment
Share on other sites

Guest Anonymous

Re: MYSQL.PHP

try contacting your hosting company about the issue am rather sure it's on there side with the problem.

Link to comment
Share on other sites

Re: MYSQL.PHP

ok so i may sound like a noob, but i tried adding msyql_close($c) to the end of mysql.php

 

<?

$c=mysql_connect('***.***.com','******_******','password') or die('Sorry, technical faults have slowed down this site, please try again later.');

mysql_select_db('*****_****',$c);

mysql_close($c);

?>

But this simply stopped all my queries from working, showing an error,

 

Warning: mysql_query(): 4 is not a valid MySQL-Link resource in /home/www/SITENAMEHERE/index.php on line 11

If mysql_close() is indeed the answer, where should it be put?

 

The host can also allow more connections.

This is what I suggested to the host when they replied with the close sql connections.

Again, any help would be greatly appreciated.

Link to comment
Share on other sites

Re: MYSQL.PHP

placing mysql close at the end of a script is likely to change nothing. php actually does you the favor of closing the database connection at the end of a script anyways, UNLESS you EXPLICITLY ask for a persistent connection.

But don't take my word for it, make a script "page1.php" and connect to the database, but don't close the connection. Then make a page "page2.php" and put some queries in there, but don't open a connection. And watch, you won't be able to connect to the database, even if you load page1.php first, and then page2.php.

;)

Web host, it really does sound like something they need to fix.

Link to comment
Share on other sites

Re: MYSQL.PHP

If someone is refreshing pages greatly this causes a problem.

It opens multiple connections for that user till it clears the database. thus multiple connections open.

now get a few people doing this.

You can fix this by:

disable auto refreshing, clickers in your site.

require the form buttons to be used.

Generate a log in the database and log the time of there last action. if it is under 2 seconds warn them to slow down. This is the nice way of doing it. The not so nice way is have your host install something to auto block them on massive amounts of connections limiting there connections to say 5 per ip.

This will slow it. However taking all this into account.

If you are on a cheap unlimited host forget all of the above first and get a real host that can handle the higher loads, and work with you the paying customer.

I raise max connections for clients all the time on there boxes. No reason why they cant do it for you.

TJ

Link to comment
Share on other sites

Re: MYSQL.PHP

thank you for your support here, i think the problem is now underhand.

btw i do have a real host lol :-D

i would post name, but i would deem it as advertising so can only assume admin would as well.

if any problem arises again i will be sure to ask here.

+1 to all.

Link to comment
Share on other sites

Re: MYSQL.PHP

Hi again, as previously mentioned, i believed the problem to be underhand since doing everything suggested here. However

since the last post, although i myself have not experienced any problems i have had numerous emails telling me that the error still exists, is there anything else i can do?

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