What is difference between mysql_connect and mysql_pconnect in php ?

mysql_connect() and mysql_pconnect() deos the work for connection the database while there is little bit difference between them , p stands for stands for persistence connection.

While we are using mysql_connect() function , each and every time it opens and close the databases  connection  depending upon the request .
where as ,

In the case of the mysql_pconnect() :

 While connecting mysql_pconnect() function will check for persistence , that is if it already opened with the same host, username and password .  If once found it will return instead of opening the new connection .

The connection to the sql server will not close by default once the connection is opened , so you need to use the mysql_close() function to close the connection .

Thus , mysql_pconnect() is useful when there exist lots of traffic on your site because at the same time it will not open the connection rather it will take from pool which will increase the efficiency of site .

But in the general case mysql_connect() is best to use  .

Leave a Reply

Your email address will not be published.Required fields are marked *