要將數據庫導入到PHP頁面,可以使用以下步驟:
例子(使用mysqli):
$servername = "localhost";
$username = "root";
$password = "password";
$dbname = "mydatabase";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
例子:
$sql = "SELECT * FROM mytable";
$result = $conn->query($sql);
例子:
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "ID: " . $row["id"]. " - Name: " . $row["name"]. "
";
}
} else {
echo "0 results";
}
例子:
$conn->close();
通過以上步驟,您可以將數據庫導入到PHP頁面,并在該頁面上顯示數據庫中的數據。您可以根據您的具體需求進行修改和擴展。