Home / mySQL / mysql_connect() and mysql_pconnect()

mysql_connect() and mysql_pconnect()

Hi all,
Nobody knows what are the main differnce between MYSQL_CONNECT() and MYSQL_PCONNECT(). MYSQL_CONNECT() and MYSQL_PCONNECT() are working for database connection. But these two have some little diffrence. In mysql_pconnect(), ‘p’ stands for persistance connection.

The mysqli_connect() function opens a new connection to the MySQL server. Every time it is opening and closing the database connection, depending on the request .



Mysql_pconnect checks if that if the same host, username and password connection is already opened an identifier for it will be returned instead of making a new connection. mysql_pconncet() is useful when you have a lot of traffice on your site

Difference between mysql_connect() and mysql_pconnect()


  • mysql_connect can be used to close the connection.Every time it is opening and closing the database connection, depending on the request .
  • Here database is opened everytime when the page is loaded in MYSQL connect

  • When the page is loaded, the database is loaded everytime
  • It is used to close the connection
  • Example:<
    $conn = mysql_connect(‘host’, ‘mysql_user’, ‘mysql_password’);
    if (!$conn)
    die(‘Could not connect: ‘ . mysql_error());
    echo ‘Connected successfully’;

    • host: Specifies a host name or an IP address like localhost.
    • mysql_user: Specifies the MySQL username
    • mysql_password: Specifies the MySQL password


  • We use the mysql_pconncet(), it initially tries to find an open persistent connection.
  • The mysql_pconncet() opens persistant connection
  • The mysql_pconnect() does not support the close connection
  • mysql_pconnect() cannot close the connection. Here open a persistant connection to the database

  • Here database need not be connected everytime.
  • The database need not be connected every time in mysql_pconncet().

If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

Leave a Reply

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