Maintaining db communication on different pages

I am a student. Is there a way to stay connected to the mysql database when the user goes to the next page.

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

Or does it even matter on a low traffic site?

Yesterday I read a message about something related to the sessions, and the defendant talked about sending a header-type (?) File.

Thanks.

+4
source share
4 answers

Yes and no. As soon as the user moves to the next page, for all purposes and tasks they are no longer connected to the database.

Your script (on the next page) will still need to open a connection for them. mysql_pconnect() will ensure that the actual connection they used is still available when it wants to, but it can also cause an excessive number of apache/mysql connections to wait uselessly.

I would strongly recommend not using it unless your tests show that it provides a significant increase in performance. As a rule, for most applications (especially when you are studying), I will not worry about constant connections. Note the warning in the PHP manual

+1
source

It doesn't matter if you don't get a ton of queries, but php has mysql_pconnect (pconnect) for persistent connections to MySQL. each apache instance will maintain an active connection to mysql, which can be used without reconnecting.

+1
source

I believe that you are looking for something like mysql_pconnect () that establishes a permanent connection to the database.

0
source

I really can not understand your question, if you extracted data from db, you usually do something with it. And if you want to get data from db, you usually do this. Some Framworks and Library make these points a little lighter.

Here is the usual process method.

 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
source

All Articles