0

this is the error i got trying to host a website for the first time.

Fatal error: Uncaught Error: Call to a member function execute() on bool in /storage/ssd3/611/13067611/public_html/app/database/db.php:47 Stack trace: #0 /storage/ssd3/611/13067611/public_html/app/controllers/topics.php(15): selectAll() #1 /storage/ssd3/611/13067611/public_html/index.php(3): include('/storage/ssd3/6...') #2 {main} thrown in /storage/ssd3/611/13067611/public_html/app/database/db.php on line 47

Also in the db.php file, i have a selectAll function. This is the code below please.

//Select all function
function selectAll($table, $conditions = [])
{
    global $conn;
    $sql = "SELECT * FROM $table";
    if (empty($conditions)){
        $stmt= $conn->prepare($sql);
        $stmt->execute();
        $records = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
        return $records;
    }
    else{
        $i = 0;
        foreach ($conditions as $key => $value){
            if ($i === 0) {
                $sql = $sql . " WHERE $key=?";

            } else {
                $sql = $sql . " AND $key=?";

            }
            $i++;
        }
        $stmt= executeQuery($sql, $conditions);
        $records = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
        return $records;
    }
}

please any help on how to deal with this error will be much appreciated. Also i was hosting on 000Webhost.com if that is also neccessary. Thank you all

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • Your prepare failed. Double-check your database and tables on the live server to make sure you've copied over your database structure. – aynber May 21 '20 at 11:38
  • please i've checked the live database and everything is ok – Osik Newton May 21 '20 at 11:56
  • 1
    If a query does not work as expected, check for [mysqli errors](http://php.net/manual/en/mysqli.error.php) to find out why it failed. – aynber May 21 '20 at 11:58
  • please is something wrong with this line $stmt->execute(); in my code? that is the line 47. – Osik Newton May 21 '20 at 12:27
  • 1
    `$stmt` is false because your prepare failed. Check for [mysqli errors](http://php.net/manual/en/mysqli.error.php) after your prepare to find out why it failed. – aynber May 21 '20 at 12:28
  • please can you show me how to check for the mysqli error? – Osik Newton May 21 '20 at 12:48

0 Answers0