Connecting Tech Pros Worldwide Help | Site Map

mySQL connection limit

  #1  
Old July 17th, 2005, 02:36 AM
Titus Cheung
Guest
 
Posts: n/a
Hello,

Thought I read somewhere saying that there is a limit to how many
connections are available per mySQL account or something like that. Can
someone please clarify?

I wrote a PHP tool that uses a different PHP file whenever someone hit an
HTML form button (ie Submit). It turned out that each one of these PHP
files need to re-open the link to the mySQL database by the following
snippet or else that particular file won't work:

@ $link = mysql_connect("localhost", "myself", "");
if (!$link == 1)
echo "Connection to database failed.";

But I thought that PHP will use the already opened link from the previous
PHP file and as a result the above is not necessary. Is this true, or only
if it is within the same PHP file? And would having called the above code
snippet too many times cause mySQL to prevent user "myself" from connecting
again?

Thanks


  #2  
Old July 17th, 2005, 02:36 AM
Michael Fuhr
Guest
 
Posts: n/a

re: mySQL connection limit


"Titus Cheung" <titus@ieee.org> writes:
[color=blue]
> Thought I read somewhere saying that there is a limit to how many
> connections are available per mySQL account or something like that. Can
> someone please clarify?[/color]

Both PHP and MySQL have configuration settings that can limit a
user's database connections. See the documentation:

http://www.php.net/mysql
http://www.mysql.com/documentation/
[color=blue]
> I wrote a PHP tool that uses a different PHP file whenever someone hit an
> HTML form button (ie Submit). It turned out that each one of these PHP
> files need to re-open the link to the mySQL database by the following
> snippet or else that particular file won't work:
>
> @ $link = mysql_connect("localhost", "myself", "");
> if (!$link == 1)
> echo "Connection to database failed.";
>
> But I thought that PHP will use the already opened link from the previous
> phP file and as a result the above is not necessary.[/color]

Without a call to mysql_connect() or mysql_pconnect(), how would
PHP know which database you want to connect to? How would PHP know
which "previous" file's database connection to re-use?

You might be thinking of persistent connections, where you can use
a previously-established connection by calling mysql_pconnect().

http://www.php.net/features.persistent-connections
http://www.php.net/mysql_pconnect
[color=blue]
> Is this true, or only if it is within the same PHP file? And
> would having called the above code snippet too many times cause
> mySQL to prevent user "myself" from connecting again?[/color]

It's possible that repeated connections would eventually fail --
you'll have to check your PHP and MySQL configurations to see what
the limits are.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
php 5 and mysql failure Caffeneide answers 10 June 2nd, 2008 11:35 AM
MySQL millions row OLTP dimensioning Federico answers 4 November 2nd, 2006 02:05 PM
Non-stop queries coming from ??? XP, MySQL 5.0.15 Good Man answers 1 December 9th, 2005 04:45 PM
Formatting the MySQL Timestamp in php RT answers 4 July 17th, 2005 10:19 AM