我有一個數據庫,db_db我想要在我的瀏覽器顯示數據。我已經把這個php代碼(display.php)放在/ var/www /下,並試圖訪問localhost/display.php
。雖然每次遇到「服務器錯誤」,但網站在檢索http://localhost/display.php
時遇到錯誤。它可能因維護而關閉或配置不正確。服務器錯誤,試圖顯示數據從MySQL數據庫在PHP
的代碼如下:
<?php
//make conn
$link = mysql_connect('localhost', 'root', '');
//select db
mysql_select_db('db_db') or die("Unable to select db");
$sql = "SELECT * FROM results WHERE jobid = 'abc'";
$records = mysql_query($sql);
?>
<html>
<head>
<title> Result Info </title>
</head>
<body>
<table width="600" border = "1" cellpadding = "1" cellspacing= "1">
<tr>
<th>id</th>
<th>name</th>
<tr>
<?php
while($result = mysql_fetch_assoc($records)){
echo "<tr>";
echo "<td>.$result['id'].</td>";
echo "<td>.$result['name'].</td>";
echo "</tr>";
}//end while
?>
</table>
</body>
</html>
不知道我要去哪裏錯了。
這聽起來更像是一個Apache的問題。你能檢索一個簡單的HTML頁面嗎? – Robbert
是的,我有一個info.php(phpinfo())在相同的路徑,即/ var/www /,它返回了'localhost/info.php'上預期的值 –
mysql_ *函數已被棄用。你應該考慮使用PDO或mysqli。我也在生成表格單元的代碼中看到一個錯誤。 'echo「。$ result ['id']。」;'應該是'echo「」。 $ result ['id']。 「」;' – Robbert