I’m a PHP newbie working a some scripts to display some news articles from a databse and wanted to find out a couple of things.
- For opening a connection to a MySQL database, which is a better option
mysql_connectormysql_pconnect? - What are the advantages or drawbacks of using a persistent connection to the database?
- And in what kind of scenario will a persistent connection be called for?
If you are going to write a web page there is no need of persistent connection. It takes too much resources. Use mysql_connect. Minimize the time your db connection is open and not used as much as you can. Open, fetch what you want, close. It doesn’t need to stay open while the users are just reading. The connection will be used eventually if they respond – INSERT/go to another page..
Here are some good points about NOT USING persistent connection in web applications