This question already has an answer here:
Mysqli update throwing Call to a member function bind_param() error [duplicate]
                                
                                    (1个答案)
                                
                        
                                4年前关闭。
            
                    
从本地主机迁移到Web服务器后,出现此错误。可能是由于Web服务器上的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();
 ?>

最佳答案

我认为您的查询失败,因为$conn->query($sql)将返回FALSE(请参见mysqli::query)。

请在您的代码中添加以下代码以获取错误消息:

if (!$result) {
    printf("Error: %s\n", $conn->error);
}

关于php - 致命错误:在第17行上的…上的非对象上调用成员函数fetch_assoc(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32452169/

10-13 23:16