This function Open a persistent connection to a MySQL server.

mysql_pconnect() works much like mysql_connect() but with two major differences.

First, when connecting, the function would first try to find a (persistent) link that’s 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, The connection will not be closed when the execution of the script ends (mysql_close() will not close connection opened by mysql_pconnect()). It will stay open for future use

Syntax: mysql_pconnect(server,user,pwd,clientflag)


The first argument “server” is Optional. It specifies the server to connect to (can also include a port number. e.g. “hostname:port” or a path to a local socket for the localhost). Default value is “localhost:3306”

The second argument “user” is Optional. It specifies the username to log in with. Default value is the name of the user that owns the server process.

The third argument “password” is Optional. It specifies the password to log in with. Default is “”.

The fourth argument “clientflag” 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


$con = mysql_pconnect("localhost","mysql_user","mysql_pwd");
if (!$con)
  die('Could not connect: ' . mysql_error());
eXTReMe Tracker