开发者

keeping db connection active across pages

开发者 https://www.devze.com 2022-12-16 12:24 出处:网络
I\'m a learner. 开发者_Python百科 Is there a way to stay connected in to the mysql database as the user is taken to the next page.

I'm a learner. 开发者_Python百科 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.


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 warning in the PHP Manual


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.


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


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.
0

精彩评论

暂无评论...
验证码 换一张
取 消