mysql_pconnect在单一进程,特别是一直保持执行的监控程序,特别适用。
mysql_pconnect用法和mysql_connect类似:
复制代码 代码如下:
$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'];
?>
复制代码 代码如下:
$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);
复制代码 代码如下:
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");//持久连接
mysql_select_db($this->dbname,$conn);
mysql_query("SET NAMES {$this->code}");
}
public function query($sql){
$result=mysql_query($sql);
return $result;
}
}
?>