MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 16th, 2000, 05:43 AM
Borgeat Borgeat is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 14 Borgeat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hello,

I have three SELECT in a page.php, which solution is the best ?

1.$link=mysql_connect(…)
SELECT….x
SELECT…y
SELECT…z
mysql_close($link) ;

or
2. $link=mysql_connect(…)
SELECT …x.
mysql_close($link) ;
$link=mysql_connect(…)
SELECT…y.
mysql_close($link) ;
$link=mysql_connect(…)
SELECT…z.
mysql_close($link) ;

thank you

Reply With Quote
  #2  
Old August 16th, 2000, 09:18 AM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 13
Send a message via AIM to rod k
Don't use mysql_close() before you are finished. There's a lot of overhead in opening a connection to mysql. In fact, I NEVER use mysql_close(). If I'm using a module version I use mysql_pconnect() and mysql_close() has no effect. With mysql_connect() the connection is closed when the script finishes executing so there's no reason to specifically close it.

Reply With Quote
  #3  
Old September 4th, 2000, 07:31 PM
mstembri mstembri is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Location: Norcross, GA
Posts: 458 mstembri User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Rod, if the administrator does not have access to the my.cnf file and the host will not alter the my.cnf file - what else can I do about a plague of "too many connection" errors.

I've tried mysql_free_result($resultofquery) and even mysql_close($db) - no dice.

A lot of work and learning has gone into the project I'm working on, and I'd hate to throw it all away because of a seemingly uncorrectable error. It seems the 'too many connections' error is not that uncommon, either.

- Mike

Reply With Quote
  #4  
Old September 4th, 2000, 11:37 PM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 13
Send a message via AIM to rod k
A unique connection is only opened for unique host/user pairs. i.e. if you use mysql_[p]connect('localhost','user','pass') only 1 connection will be used by all scripts that call localhost with the user of 'user'. If you are on a dedicated server that only ever uses one mysql user and one mysql host for all web pages, there will only ever be one connection to mysql.

The problem lies in virtual hosting. It's not uncommon to have 250 different sites on one server, each with it's own mysql user obviously. AIUI, each connection uses about 1 MB of memory so the number of connections are limited (less than 100 with 128 MB of memory) so if more than one site has a script requesting a connection, the server will run out of connections. (not to say that the loss of RAM will cause this but if max_connections are set too high for the amount of RAM the machine will crash anyway.)

Your solution - move to a different host... or demand that your current host place you on a machine that has enough RAM to support the number of virtual hosts.

Reply With Quote
  #5  
Old September 5th, 2000, 07:54 AM
mstembri mstembri is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Location: Norcross, GA
Posts: 458 mstembri User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Thank you for the explanation.

I'll call my hosting company and see what they are willing to do.

- Mike

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > mysql_connect/mysql_close


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway