Mysql function
mysql_pconnect() opens a persistent connection to a MySQL server.
Syntaxresource mysql_pconnect ( [string server [, string username [, string password [, int client_flags]]]])
string server (optional): server to connect, includes Desired host, with optional port or socket component
string user_name (optional): Username to log in with
string password (optional): Password to log in with
int client_flags (optional): Can be a combination of the following constants:
- MYSQL_CLIENT_SSL - Use SSL encryption
- MYSQL_CLIENT_COMPRESS - Use compression protocol
- MYSQL_CLIENT_IGNORE_SPACE - Allow space after function names
- MYSQL_CLIENT_INTERACTIVE - Allow interactive timeout seconds of inactivity before closing the connection
Returns a positive MySQL persistent link identifier on success, or FALSE on error.
mysql_pconnect() establishes a connection to a MySQL server.
mysql_pconnect() works same as mysql_connect with two differences.
First, when connecting, the function would first try to find a (persistent) link that is already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.
Second, Mysql_connect opens a new connection each time a PHP page is called up, and closes the connection down again at the end of the request. Mysql_pconnect() will also open a new connection when a PHP page is called up (at any rate, it will the first time after a server reboot), but it will NOT close the connection at the end of the request - instead, it will save it in a connection pool so that a subsequent request can continue to use the same connection.
Example:
<?php
//Attempt to establish persistent connection to the default database server
$link = mysql_pconnect("mysql_host", "mysql_user", "mysql_password")
or die ("Could not connect");
?>
If you want to establish a non-persistent MySQL connection, use
mysql_connect() instead.