Fatal error: Call to a member function rowCount() on a non-object in /opt/lampp/htdocs/xampp/assets/update.php on line 6

 $sql = "SELECT * from idea ORDER BY datetime DESC LIMIT 50;";
$result = $pdo->query($sql); if($result->rowCount() > 0 && !empty($result)) // line 6
{
foreach ($result as $row)
{
$id = $row['id'];
$title = $row['title'];
$idea = $row['idea']; echo '<span class="idea" id="'.$id.'"><strong style="color: #0081C5">' . $title . "</strong> - " . $idea . ' <a class="delete" href="#">[Delete]</a></span>';
}
}
一般如果你的sql语句查询出现错误时,没有进行$result 的判断,直接使用$result -> rowCount()会出现这种错误。
上一篇:Scanf函数输入字符串


下一篇:Can't connect to local MySQL server through socket '/opt/lampp/var/mysql/mysql.sock' (2)