When connecting, this function will first attempt to find a (persistent) connection with the same user name and password on the same host, and if found, return this connection identity without opening a new connection. Second, when the script finishes executing the connection to the SQL server is not closed, the connection will remain open for later use (Mysql_close () will not close the connection established by Mysql_pconnect ().
PHP tutorial MySQL tutorial _connect and mysql_pconnect functions and examples tutorial
Mysql_connect
Mysql_connect ($this->root, $this->user, $this->pass)
/*
Mysql_connect, a single rhetorical question user does not frequently call the database tutorial, there is no need to keep the connection, and MySQL connection number is also limited, use timely access is more frequent, it is best to use mysql_connect, so that the use of resources can be released immediately, otherwise, Easily lead to resource consumption
*/
Mysql_pconnect
/*
The Mysql_pconnect () function opens a persistent connection to the MySQL server
*/
$con = mysql_pconnect ("localhost", "Mysql_user", "mysql_pwd");
if (! $con)
{
Die (' Could not connect: '. Mysql_error ());
}
Class testlinkmysql{
public $conn;
Public $root = ' localhost ';
Public $user = ' root ';//' Loupan ';
Public $pass = ' root ';//' Loupandsffds ';
Public $db = ' dbname ';
Public $charset = ' GBK ';
Public $links = ' C '; Title
function __construct () {
if (! $this->conn)
{
$this->connect ();
}
}
function __destruct () {
if ($this->conn)
{
$this->close ();
}
}
function Mysqlconnect ()
{
try{
if (' p ' = = $this->links)
{
$this->conn = mysql_pconnect ($this->root, $this->user, $this->pass) or Die (Mysql_error ());
}
Else
{
$this->conn = mysql_connect ($this->root, $this->user, $this->pass) or Die (Mysql_error ());
}
mysql_select_db ($this->db, $this->conn);
mysql_query ("Set Names ' $this->charset '");
}catch (Exception $e) {
Echo ' Database connection failed, please contact the relevant personnel! ';
Exit
}
}
function Close ()
{
Mysql_close ($this->links);
}
}
/*
Summarize:
Mysql_pconnect () and mysql_connect () are very similar, but there are two main differences:
When connecting, this function will first attempt to find a (persistent) connection with the same user name and password on the same host, and if found, return this connection identity without opening a new connection.
Second, when the script finishes executing the connection to the SQL server is not closed, the connection will remain open for later use (Mysql_close () will not close the connection established by Mysql_pconnect ().
This site original tutorial reproduced annotated source http://www.bKjia.c0m/phper/php.html
http://www.bkjia.com/PHPjc/630873.html www.bkjia.com true http://www.bkjia.com/PHPjc/630873.html techarticle when connecting, this function will first try to find a (persistent) connection that has been opened with the same user name and password on the same host, and if found, returns this connection ID instead of ...