Connecting to MySQL

Reply

Join Date: Jan 2005
Posts: 2
Reputation: easilythebest is an unknown quantity at this point 
Solved Threads: 0
easilythebest easilythebest is offline Offline
Newbie Poster

Connecting to MySQL

 
0
  #1
Jan 15th, 2005
Hi,

I am creating a database driven website - and I have the content stored in a mysql database at the moment. At the moment each page starts with the script:

$connect = mysql_connect('$host', '$username', '$password');

$select = mysql_select_db('$database', $connect);

This works fine, but if Iv been playing around with the site for too long, it comes back with an error that too many database connections are open.

I have a few questions:

1) Does the script above open a new connection each time it is executed?
2) If so how can I reuse a connection across pages?
3) If not how would I stop 'too many connections' from being opened?

Many Thanks

Steve
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 3
Reputation: HeadBuilder is an unknown quantity at this point 
Solved Threads: 0
HeadBuilder HeadBuilder is offline Offline
Newbie Poster

Re: Connecting to MySQL

 
0
  #2
Jan 15th, 2005
1. PHP would close all open connections after the script terminates.
2. -
3. It's probably a cause of some other sites on the same server opening too many connections that the mysql is unable to cope. Are you on shared hosting btw?
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 2
Reputation: easilythebest is an unknown quantity at this point 
Solved Threads: 0
easilythebest easilythebest is offline Offline
Newbie Poster

Re: Connecting to MySQL

 
0
  #3
Jan 15th, 2005
No I am on dedicated hosting. The pages on my site normally load quickly, but every now and again, they take way too long to load.
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 294
Reputation: zippee is an unknown quantity at this point 
Solved Threads: 6
zippee's Avatar
zippee zippee is offline Offline
Posting Whiz in Training

Re: Connecting to MySQL

 
0
  #4
Jan 16th, 2005
I have been "reading" MySQL manual yesterday...

1. -
2. MySQL allow 4000 (or 400??) simultaneous connections. After you close the database, it will take 3-4 minutes before the connection can be reuse.
3. You can use SSI to open the connection of a page and only close it when leaving the page. Alternatively, but I've never try before, you may use session to open (session start) and close (session end) the connection when someone visiting to and leaving the site, respectively.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC