mysql教程_db_query 與mysql_query 查詢區別
mysql_db_query
/*
mysql_db_query語法: int mysql_db_query(string database, string query, int [link_identifier]);
mysql_db_query函數用來送出查詢字符串 (query) 到後端的 MySQL 數據庫教程中。而可省略的參數 link_identifier 若不存在,程序會自動尋找其它 mysql_connect() 連接後的連接代碼。發生錯誤時會返回 false
*/
$server ='www.111cn.net';
if (!$link = mysql_connect($server, 'mysql_user', 'mysql_password')) {
echo 'Could not connect to http://www.111cn.net mysql';
exit;
}
else
{
$query = mysql_db_query('db',$sql,$link);
if( $query )
{
while ($row = mysql_fetch_assoc($query)) {
echo $row['foo'];
}
mysql_free_result($query);
}
else
{
echo "DB Error, could not query the databasen";
echo 'MySQL Error: ' . mysql_error();
exit;}
}
//下面來看看關於 mysql_query函數實例
mysql_query
$cn = mysql_connect($server,'root','root');
mysql_select_db('db',$cn); //我們用mysql_db_query這裡不要設置
$result = mysql_query( $sql );
while ($rs = mysql_fetch_array($result))
{
echo $row['foo'];
}
mysql_free_result($result);
/*
本站原創教程轉載注明來源php教程er/php.html">http://www.111cn.net/phper/php.html
*/
?>