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()会出现这种错误。
posted @ 2018-01-16 14:20  Ryan_zheng  阅读(524)  评论(0编辑  收藏  举报