我有下面的代碼,當我嘗試打開網頁我得到的消息PHP是不是真正執行
「;} //關閉數據庫連接mysql_close($ CON);?>
正如你可以看到我關閉了它。可有人請幫助我。謝謝。
<html>
<head>
<title>Retrieve data from database </title>
</head>
<body>
<?php
$host='localhost';
$user='xxxxx';
$pass='xxxxx';
$database='xxxxx';
// Connect to database server
$con=mysql_connect($host, $user, $pass) or die (mysql_error());
// Select database
mysql_select_db($database) or die(mysql_error());
// SQL query
$strSQL = "SELECT * FROM contact_list";
// Execute the query (the recordset $rs contains the result)
$rs = mysql_query($strSQL);
// Loop the recordset $rs
// Each row will be made into an array ($row) using mysql_fetch_array
while($row = mysql_fetch_array($rs)) {
// Write the value of the column LastName (which is now in the array $row)
echo $row['lastname'] . "<br />";
}
// Close the database connection
mysql_close($con);
?>
</body>
</html>
mysql_已棄用。請參閱PDO/mysqli_ – Strawberry
只是FYI,[你不應該使用'mysql_'函數來創建新的代碼](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in- php) – esqew