Fatal error: Call to a member function query() on a non-object

0 Mark Tan · October 1, 2014
I tried the var_dump and it displayed the NULL result.
It does working in my local machine, but when i uploaded at hosting this error message appeared.
Thanks.

Hosting php version : 5.3.28
Local php version : 5.4.7

i did put the code at bootstrap.php

try {
    $dbc = new PDO("mysql:host=$host;dbname=$database", $username, $password);
} catch (PDOException $e) {
    //throw new exception(DB_ERROR);
}


and the model.php going to use it

public function query($sql) {
if (empty($sql)) return false;
global $dbc;
$result = $dbc->query($sql);
                $dbc = null;
                if ($result == null)
                    return false;
        $result->setFetchMode(PDO::FETCH_ASSOC);
        return $result->fetchObject();
}

Post a Reply

Replies

Oldest  Newest  Rating
0 Mark Tan · October 2, 2014
Problem solved, didn't grant the privileges of database user. 
Thanks. :)
  • 1

PHP

124,719 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators