Sunday, November 20, 2011

PHP mysql_connect Vs mysql_pconnect

  • Both "mysql_connect" and "mysql_pconnect" are used to connect MySQL database by PHP. Both are having similar function signature.
  • Main difference is, if we use "mysql_pconnect", this function would first try to find a persistant link that is already open with the same host, username and password.
  • In other words, mysql_pconnect() will try to find a connection that's already open, with the same host, username and password. If one is found, this will be returned instead of opening a new connection
  • "mysql_close" function can't close the database object if we connect the database with "mysql_pconnect" method.
  • For low traffic websites, its better to use mysql_pconnect method to increase the performance of the website. And for high traffic websites we should use "mysql_connect". Because, in high traffic, lot of database connections will be opened and they will lag the system performance.

2 comments:

  1. Why to use mysql_connect in high traffic websites??? Will it not open lot of connections and it can decrease system performance??

    ReplyDelete
  2. How to close connections opened by mysql_pconnect method.

    ReplyDelete