mysqli can't fetch database?
<p>Apparently My database function can't fetch the database?</p>

<p>Warning: mysqli::real_escape_string(): Couldn't fetch database</p>

<p>I've created a custom database class which extends MySQLi.</p>

<p>Here's how I'm constructing it. </p>

<pre><code>public function __construct(){
    $db = new mysqli(
        DB_HOST, DB_USER, DB_PASS, DB_NAME);

    $db-&gt;select_db(DB_NAME);
    return $db;
}
</code></pre>

<p>I am selecting the database, aren't I?</p>

<p>The code where this is happening is here:</p>

<pre><code>    private static function readSession($sessionId)
    {
    global $database;
    $sessionId = session_id();
    $sessionId = $database-&gt;real_escape_string($sessionId);
    $time = time();
    $result = $database-&gt;query("SELECT sessiondata FROM sessions WHERE sessionid='$sessionId' AND expiry &gt; $time");
    if ($result-&gt;num_rows &gt; 0) {
        $row = $result-&gt;fetch_array();
        return $row['sessiondata'];
    }
    return "";
}
</code></pre>

<p>The database is being initiated before the Session Management functions are being called. </p>
