要将数据库导入到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页面,并在该页面上显示数据库中的数据。您可以根据您的具体需求进行修改和扩展。