Mysql_pconnect is particularly applicable in a single process, in particular the monitoring procedures that have been maintained.
Mysql_pconnect usage and mysql_connect are similar:
Copy CodeThe code is as follows:
$conn = Mysql_pconnect ($host, $user, $pwd);
mysql_select_db ($dbname, $conn);
$result =mysql_query ("SELECT * FROM table_name where col_id = ' test_id '", $conn);
$result _detail=mysql_fetch_array ($result);
$item = $result _detail[' col_id ');
?>
Note: Using Mysql_pconnect is not a good choice when working with database requests for high concurrency, and you can consider caching and step-up issues.
PHP Persistent Connection mysql_pconnect () function can improve efficiency of battle JSP
Function usage:
Copy CodeThe code is as follows:
$dbHost = "localhost";
$dbUser = "root";
$DBPWD = "";
$dbName = "Zhoutang";
$strSQL = "Update tbluser set userlc=userlc+1 where userid=100";
$link = mysql_connect ($dbHost, $dbUser, $dbPwd) or Die (' Could not connect: '. Mysql_error ());
mysql_select_db ($dbName);
mysql_query ($strSQL);
Mysql_close ($link);
Usage and mysql_connect () are similar, there are only two differences:
First, Mysql_pconnect () 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, just returns the connection identifier for this link without opening a new connection;
Second, when the function executes, the connection to the SQL Server is not closed and the connection remains open for later use.
The Mysql_pconnect () function can greatly improve MySQL efficiency, however, this connection does not automatically shut down and can cause some problems, please note that the unused connection is closed immediately to avoid unnecessary errors.
In fact, I previously wrote a PHP persistent connection database function Mysql_pconnect (), just did not do any test, today did a small test, really good, especially when connected to the remote database, the effect is very obvious.
And then write about the application of the PHP persistent connection data inventory function (a simple MySQL class that can't be simpler)
Copy CodeThe code is as follows:
Class mysql{
Private $host;
Private $user;
Private $PW;
Private $dbname;
Private $code;
Public function __construct ($host, $user, $PW, $dbname, $code) {
$this->host= $host;
$this->user= $user;
$this->pw= $PW;
$this->dbname= $dbname;
$this->code= $code;
$this->conn ();
}
Public Function conn () {
$conn =mysql_pconnect ($this->host, $this->user, $this->pw) or Die ("Links error");//Persistent connection
mysql_select_db ($this->dbname, $conn);
mysql_query ("SET NAMES {$this->code}");
}
Public Function Query ($sql) {
$result =mysql_query ($sql);
return $result;
}
}
?>
The above method, hope to have some help, as for the test, I will not write, we test it yourself
http://www.bkjia.com/PHPjc/325011.html www.bkjia.com true http://www.bkjia.com/PHPjc/325011.html techarticle Mysql_pconnect is particularly applicable in a single process, in particular the monitoring procedures that have been maintained. Mysql_pconnect usage is similar to mysql_connect: Copy code code as follows: PHP $conn = my ...