PHP PDO class programming:Fatal error: Call to a member function fetchAll() on boolean

后端 未结 1 1931
没有蜡笔的小新
没有蜡笔的小新 2021-01-28 08:23

I am new to the class programming in php ,Here is my database class.

class Database
{
    private $_connection;
    private static $_instance; //The single insta         


        
1条回答
  •  北荒
    北荒 (楼主)
    2021-01-28 09:11

    You need to return the $result only in the run() method:

    public function run($sql)
        {
            $result=$this->_connection->prepare($sql);
            $result->execute();
            return $result;
        }
    

    Returning the $result->execute(); is returning true because the execute() succeeded. You need to return the current state of $result.

    See if that works.

    0 讨论(0)
提交回复
热议问题