要將數(shù)據(jù)庫導(dǎo)入到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();
通過以上步驟,您可以將數(shù)據(jù)庫導(dǎo)入到PHP頁面,并在該頁面上顯示數(shù)據(jù)庫中的數(shù)據(jù)。您可以根據(jù)您的具體需求進行修改和擴展。