Use mysql_connect or mysql_pconnect?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PhpMachine
Forum Commoner
Posts: 42
Joined: Thu Apr 19, 2007 11:26 am

Use mysql_connect or mysql_pconnect?

Post by PhpMachine »

Hi

Let us say you have a website where you, in a lot of different classes, connect to your database to
retrieve/update information.

Should you then use mysql_connect or mysql_pconnect?
Or should you only once (for instance in "index.php"), create the connection, and then pass that link
to all classes that need to work with the database?

What are the advantages and disadvantages using mysql_connect, mysql_pconnect?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Persistent connections will persist until you explicitly close them. In my opinion, not good for high traffic web sites or sites with lots of readable content. (why would you want your database connection open for X minutes while user is reading)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Yes, I would recommend using mysql_connect until you find that you actually need persistent connections (which you probably won't).
(#10850)
PhpMachine
Forum Commoner
Posts: 42
Joined: Thu Apr 19, 2007 11:26 am

Post by PhpMachine »

When do you actually need persistent connections?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

PhpMachine wrote:When do you actually need persistent connections?
Generally, you don't, ever.
Post Reply