Fatal error: Call to a member function fetchALL() on a non-object - using PDO on a Microsoft Access Database

后端 未结 2 1717
执念已碎
执念已碎 2020-12-20 10:05

Good Afternoon!

I have made a connection class to a Microsoft Access Database (which works). However my problem lies where I\'m trying to use this class to execute a

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-20 10:50

    $result is just a boolean that indicates whether the query was successful or not. The fetchAll method is on PDOStatement, so it should be:

    while ($row = $sql->fetch(PDO::FETCH_ASSOC)) {
    

    You're also executing the statement wrong, it should be:

    $result = $sql->execute();
    

    The method you used is for executing a SQL string without first preparing it. You could instead do:

    $result = $pdoConnection->exec("SELECT * FROM celebs");
    while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
    

提交回复
热议问题