在php中連接數據有mysql_connect() 函數或mysql_pconnect()函數來完成,下面我給大家php入門者簡單介紹介紹。
常用連接函數mysql_connect()
mysql_connect(servername,username,password);
長連接函數mysql_pconnect()
mysql_pconnect(servername,username,password);
代碼如下 復制代碼<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// some code
?>
說的是mysql_pconnect,怎麼能繞開MySQL的設置。影響mysql_pconnect最重要的兩個參數就是wait_timeout和interactive_timeout
<?php
$conn = mysql_pconnect("localhost","root","123456") or die("Can not connect to MySQL");
echo "MySQL線程號:". MySQL_thread_id($conn). "<br />";
echo "Apache進程號". getmypid();
?>