Function name: mysql_pconnect()
Applicable version: PHP 4, PHP 5
Function Description: The mysql_pconnect() function is used to open a persistent connection to the MySQL server. Unlike the mysql_connect() function, the mysql_pconnect() function attempts to reuse the established persistent connection, and if it exists, it will return the connection directly without reconnecting it.
Syntax: resource mysql_pconnect ( [string $server = ini_get("mysql.default_host") [, string $username = ini_get("mysql.default_user") [, string $password = ini_get("mysql.default_password") [, int $client_flags = 0 ]]]] )
Parameter description:
- $server (optional): The MySQL server address, default is the value of the mysql.default_host configuration item in the php.ini file.
- $username (optional): The MySQL username, default is the value of the mysql.default_user configuration item in the php.ini file.
- $password (optional): The MySQL password, default to the value of the mysql.default_password configuration item in the php.ini file.
- $client_flags (optional): A constant that specifies connection options and behavior, defaults to 0.
Return Value: If successful, the function returns a MySQL connection identifier (resource type), and if failed, FALSE.
Example: <?php $host = 'localhost'; $user = 'root'; $pass = 'password'; $conn = mysql_pconnect($host, $user, $pass); if (!$conn) { die('连接数据库失败:' . mysql_error()); } else { echo '成功建立持久连接'; } mysql_close($conn); ?-->
Notes:
- The mysql_pconnect() function prioritizes the existing persistent connection when connecting to the MySQL server, and if there is no reusable connection, a new persistent connection is created.
- When using persistent connections, you need to manually close the connection, using the mysql_close() function.
- The mysql_pconnect() function is marked as deprecated after PHP 5.5.0. It is recommended to use the mysqli or PDO extension instead.
- After PHP 7.0.0, the mysql_pconnect() function has been removed and is no longer available.