views:

123

answers:

4

I'm a learner. Is there a way to stay connected in to the mysql database as the user is taken to the next page.

For example, the db connection is made, the user is logged in, and then goes to the next page to access a table in the database. Instead of having to make the db connection again, is there a way to keep the previous connection active?

Or does it matter at all in a low-traffic site?

I read a post yesterday about something related to sessions, and the responder talked about sending a "header-type" (?) file.

Thank you.

+1  A: 

it wont matter unless you're getting a ton of requests, but php has a mysql_pconnect (pconnect) for persistent connections to mysql. each instance of apache will keep around an active connection to mysql that can be used without reconnecting.

jspcal
A: 

I believe you're looking for something like mysql_pconnect(), which establishes a persistent connection to the database.

Kaleb Brasee
A: 

I realy cant understand your question, if you have fetched datas from db you usualy do some stuff with it. And if you want fetch data from db you do usualy this points. Some Framworks and Library makes this points a bit easiyer.

Here is the usual way of the process.

1. Make connection to the db.
2. Select a db.

3. Send a query to db.
4. Fetch the results.

5. Do some funy stuff with it.
streetparade
A: 

Yes and no. Once the user goes to the next page, for all intents and purposes they are not connected to the database anymore.

Your script (on the next page) will still need to open the connection for them. mysql_pconnect() will ensure the actual connection they used is still available when they want it next, however, it can also cause excess number of apache/mysql connections to wait around uselessly.

I'd strongly suggest not using it unless your benchmarks show that it provides a significant gain in performance. Typically, for most applications (especially when you're learning), I would not bother with persistent connections.

(note the big warning in the PHP manual http://us.php.net/mysql_pconnect#function.mysql-pconnect.notes)

Owen