What is the difference between mysql_connect() and mysql_pconnect()?
Tuesday, February 16, 2010 11:19When they are using mysql_connect() function, every time it is opening and closing the database connection, depending on the request .
mysql_connect() and mysql_pconnect() both are working for database connection but with small difference. In mysql_pconnect(), ‘p’ stands for persistance connection.
But in case of mysql_pconnect() function,
First, when connecting, the function would try to find a (persistent) connection that’s already open with the same host, username and password. If three is found, an identifier for it will be returned in lieu of opening a new connection.
Second, the connection to the SQL server won’t be closed when the execution of the script ends. In lieu, the connection will remain open for future use (mysql_close() won’t close connection established by mysql_pconnect()).
mysql_pconncet() is useful when you have a lot of traffice on your site. At that time for every request it won’t open a connection but will take it from the pool. This will increase the efficiency of your site. But for general use mysql_connect() is best.


