«

»

Jun 06

Mysql_connect and Mysql_pconnect

Mysql_connect and mysql_pconnect both are used to connect the database. Mysql_pconnect use for open a persistent connection means connection is not closed and enable for future use. Mysql_pconnect is much like similar to mysql_connect, but have some difference .

  1. Mysql_pconnect try to find connection which is already open with same host, username and password. If found then this will return and not new connection. But Mysql_connect not check for open connection and it will open new connection every time and when execution of script is end then it will close automatically.
  2. In Mysql_pconnect, the connection will not closed when script end the execution it will still open for future use. But in Mysql_connect, the connection will closed when script end the execution and not available for use in future.
  3. In PHP, database and php program both are hosted on same machine so, connection time is negligible and no need of persistent connection.
  4. For web connection will automatically closed when page refreshed, because http is assume every request as new request and in this case no need of persistent connection.
  5. Persistent connection required too much resource, that’s why persistent connection is discouraged

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>