944,123 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 3952
  • MySQL RSS
Jan 15th, 2005
0

Connecting to MySQL

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
easilythebest is offline Offline
2 posts
since Jan 2005
Jan 15th, 2005
0

Re: Connecting to MySQL

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
HeadBuilder is offline Offline
3 posts
since Jan 2005
Jan 15th, 2005
0

Re: Connecting to MySQL

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
easilythebest is offline Offline
2 posts
since Jan 2005
Jan 16th, 2005
0

Re: Connecting to MySQL

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.
Reputation Points: 10
Solved Threads: 7
Posting Whiz in Training
zippee is offline Offline
294 posts
since Jan 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: Database connectioin error
Next Thread in MySQL Forum Timeline: Ms Access Help Please





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC