FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


multiple mysql connections





chris20
I'm not sure if this has been mentioned or not before, and after a search I couldn't find it, also checking out that better php programming sticky didn't answer the question either.

Anyway... I've always wondered if it was really bad to connect to a mysql database, have it process a query, return the results, mysql_close that connection, and then open it up again and repeate the process.

Is it horrible to open up the same database connection multiple times, and if so how bad is it? I use include files to include a navigation for example, and in that nav I use mysql to retrieve the nav items, but outside of the nav, I also connect to the mysql database a few times per page and query it.

Any information on this would be great, thanks.
rohan2kool
not really.. it ain't THAT bad for you to open multiple connections, however keep a tab on them as it adds to the total generation time.

btw, you can still use the same connection to run as many queries as you like (even if they are across different databases).
SlowWalkere
There's nothing wrong with opening and closing the mysql connection frequently. In fact, it's generally better practice to have the connection open for as little time as possible.

Although it doesn't make much difference if you're only reading data, it can make an impact if you constantly read/write data to a database. You want a script to have a connection open for as little time as possible so that you don't get conflicts with two scripts trying to simultaneously access the same table.

- Walkere
Related topics
A "small" list of free apps
How To : Secure Your PHP Website
Using Two Internet Connections at The same time
Best Messenger
[Edit] mySQL Count
Search more then One Database
Images in MySQL
Python and CPU load
Looping through multiple mysql results
defined Constants against variable against arrays?
MySQL Remote Access/Cron
Mysql
Updating multiple MySQL rows at once
Need info on large mysql databases
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.