Jump to content

Can u please tell what is this error?


SUNIL16

Recommended Posts

Hi Friends,

 

Can u please tell me what is the below warning. till today my code is working fine. from yesterday i am getting this warning.

 

Warning: mysql_connect() [function.mysql-connect]: Too many connections in C:\Domains\theinterviewsuccess.com\wwwroot\connect.php on line 2

could not open:Too many connections

Link to comment
https://forums.phpfreaks.com/topic/129763-can-u-please-tell-what-is-this-error/
Share on other sites

Every time you query the database you open a connection to it, the max number of connections the database can handle is a configurable variable. Now, if you're using mysql_pconnect, or if you have a lot of users, then this maximum number of connections can be passed and you will get the error you're describing.

 

To help with this situation you need to include the mysql_close function after every mysql_query.

 

Or do as revraz said...

Hi Friends,

 

Thanks for your reply,

 

Below is how i am using the code to connect

 

1]

<?php $servername='my server name';   

$dbusername='my username';               

$dbpassword='password';               

$dbname='mysite';   

 

connecttodb($servername,$dbname,$dbusername,$dbpassword);

function connecttodb($servername,$dbname,$dbuser,$dbpassword)

{

global $link;

$link=mysql_connect ("$servername","$dbuser","$dbpassword");

if(!$link){die("Could not connect to MySQL");}

mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());

 

mysql_close($con);(can i close like this?)

}?>

 

 

2]

<?php

$con=mysql_connect("my server name","username","password");

 

if(!$con)

{

die('could not open:'.mysql_error());

}

mysql_close($con);

 

?>

In the above two which one is correct way? I am new to php doing some projects

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.