PDA

View Full Version : MySql Open/Close Connection question


nexadus
7-17-07, 03:47 AM
hello everyone,

i'm sort of new w/ mysql and i'm just wondering if my site requires 8 queries to load a page and it is a multi-user site (around 50-100 users), is it better to open and close a mysql connection after each query or open it and run the 8 queries and then close it?

And what's the pro's and con's for each?

B/C i know there's a limit on the number of concurrent connections and i dont want to violate it, but at the same time i dont want to keep opening and closing it b/c that takes up a lot of resources and probably will lag the db.

any suggestions from the mysql rockstars?

YvetteKuhns
7-17-07, 02:26 PM
mysql connections question already asked here (http://www.zend.com/forums/index.php?t=msg&goto=3982&S=f4b1adb181317dd5756105dbb2123c7e)

nexadus
7-17-07, 05:55 PM
thanks, and i also found on the mysql_close manual that using mysql_close() isn't usually necessary, as non-persistent open links (e.g using mysql_connect() and not mysql_pconnect() ) are automatically closed at the end of the script's execution.

YvetteKuhns
7-17-07, 05:59 PM
True, but it is good practice to close things that are open. Also, proper nesting and opening and closing of tags will help validate your code for cross-browser compatibility. Seeing an open tag without a closing tag can make your pages display differently than desired. It is better to get in the habit of including them. In the future, these things may be required.