0

Currently I'm working on a microblog just to get familiar with PHP MySQL.

I have a pretty big problem though.

Here's the php code:

   function get_all_users(){
        $query = "SELECT * FROM ".$this->prefix."users";
        if ($stmt = $this->prepare($query)){
            $stmt->execute();
            $users_array = array();
            $stmt->bind_result($id, $username, $password, $realname, $email);
            while ($stmt->fetch()){
                $oneuser = array('id'=>$id, 'user'=>$username, 'name'=>$realname, 'email'=>$email);
                array_push($users_array, $oneuser);
            }
            $stmt->close();
            return $users_array;
        } else {
            echo "get_all_users() encountered a fatal error: " . $this->error;
            exit();
        }
    }

Note that the above function is under a class that extends mysqli.

The error is:

Warning: mysqli::prepare() [mysqli.prepare]: Couldn't fetch MicrobloggingDatabase in C:\xampp\htdocs\microblog\includes.php on line 121

Warning: MicrobloggingDatabase::get_all_users() [microbloggingdatabase.get-all-users]: Couldn't fetch MicrobloggingDatabase in C:\xampp\htdocs\microblog\includes.php on line 132
get_all_users() encountered a fatal error:

Also, when i try to close the database after generating the page, i get this warning:

Warning: mysqli::close() [mysqli.close]: Couldn't fetch MicrobloggingDatabase in C:\xampp\htdocs\microblog\admin.php on line 107

any ideas?

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by ultimatebuster
0

Sorry i was being stupid. MicrobloggingDatabase is a class that extends mysqli that i created. It however, doesn't connect to MySQL upon __construct(). It connect when it's start()'ed. I forgot to do that.

*Facepalm*

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.