从localhost迁移到Web服务器后,我收到此错误。也许可能是因为webserver上的PHP版本(PHP 5.2)。有任何想法吗?
<?php
$servername ="";
$username ="uran";
$password ="";
$dbname ="";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM answer WHERE topic_key='$id'";
$result = $conn->query($sql);
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<strong>Príspevok č.:</strong> " . $row["id"]. "<br>"." <strong>Napísal:</strong> "
. $row["name"]. "<br>". $row["topic"]."<br>" . $row["reg_date"]."<br>"." <br><br>";
}
$conn->close();
?>
答案 0 :(得分:0)
我认为您的查询未能$conn->query($sql)
返回FALSE
(请参阅mysqli::query)。
请将以下代码添加到您的代码中以获取错误消息:
if (!$result) {
printf("Error: %s\n", $conn->error);
}