Home > Backend Development > PHP Tutorial > Understanding of the mysql_pconnect() function

Understanding of the mysql_pconnect() function

WBOY
Release: 2016-07-25 08:58:18
Original
1305 people have browsed it
This article introduces the usage of the mysql database connection function mysql_pconnect() in PHP. Friends in need can refer to it.

Definition and usage About the mysql_pconnect function in mysql, which is used to open a persistent connection to the MySQL server. mysql_pconnect() and mysql_connect() are very similar, but have two main differences: When connecting, this function first tries to find a (persistent) connection that is already open on the same host with the same username and password. If found, it returns the connection ID without opening a new connection. Secondly, when the script completes execution, the connection to the mysql server will not be closed, this connection will remain open for future use (mysql_close() will not close the connection established by mysql_pconnect()).

Grammar mysql_pconnect(server,user,pwd,clientflag)

Parameter Description server Optional. Specifies the server to connect to. Can include a port number, such as "hostname:port", or a path to a local socket, such as ":/path/to/socket" for localhost. If the PHP directive mysql.default_host is not defined (the default), the default value is 'localhost:3306'. user optional. username. The default value is the username of the server process owner. pwd Optional. password. The default value is an empty password. clientflag Optional. The client_flags parameter 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 name MYSQL_CLIENT_INTERACTIVE - allows interaction timeout inactivity time before closing the connection

Return value If successful, return a MySQL persistent connection identifier, otherwise return FALSE.

Tips and Notes Note: The optional clientflag parameter is available since PHP version 4.3.0. Tip: To create a non-persistent connection, use the mysql_connect() function.

Example:

<?php
//mysql_pconnect示例
$con = mysql_pconnect("localhost","mysql_user","mysql_pwd");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
?>
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template