MySQL php select 语句使用 WAMP 服务器


MySQL php select statement using WAMP server

我试图在我的 html 页面中显示数据库表,但似乎无法让它工作。(下面的代码):

<!DOCTYPE html>
<html>
<body>
<h1> Table </h1>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "Library";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
     die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM `books` ORDER BY `Category` ASC ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
     // output data of each row
     while($row = $result->fetch_assoc()) {
         echo "<br> id: ". $row["ISBN"]. " Name: ". $row["firstname"]. " - Author: " . $row["BookAuthor"]. " Category: " . $row["Category"]. " - Quantity: " . $row["Quantity"]. " - Price: " . $row["Price"]. "<br>";
     }
} else {
     echo "0 results";
}
$conn->close();
?> 
</body>
</html>

我使用的是WAMP服务器,"书籍"表位于一个名为图书馆的数据库中。但是,该表没有显示,我得到的只是显示的 php 代码。

知道出了什么问题吗?

谢谢!

  1. 您的 WAMP 是否正在运行?(检查系统托盘图标。它应该是绿色的)
  2. 你搞砸了PHP或Apache配置吗?
  3. 文件扩展名是否.php?一定是这样。
  4. 其他 PHP 是否正常显示?