Call to a member function query() on a non-object on trying to read data
<p>Hi I have been learning php from this book <a href="http://rads.stackoverflow.com/amzn/click/1430232498" rel="nofollow">PHP Solutions Dynamic Web Design Made Easy</a> and gotten to the part where I have to work with mysqli api for databases.After writing a connection function and running the script I get this error:</p>

<p><img src="http://i.stack.imgur.com/5PBbP.png" alt="enter image description here"> </p>

<p>This is my code:</p>

<pre><code>function dbConnect($usertype , $connectionType = 'mysqli'){
    $host = 'localhost';
    $db = 'phpsols';
    if($usertype == 'read'){
        $user = 'psread';
        $pwd = 'Aleczandru1989';
    }elseif($usertype == 'write'){
        $user = 'aleczandru';
        $pwd = 'Aleczandru1989';
    }else{
        exit('Unrecognized type');
    }

    if($connectionType == 'mysqli'){
        return new mysqli($host , $user , $pwd , $db) or die ('Cannot open database');
    }else{
        try{
            return new PDO("mysql:host=$host;dbname=$db", $user, $pwd); 
        }  catch (PDOException $e){
            echo 'Cannot connect to database';
            exit;
        }
    }
}

$conn = dbConnect('read');
$sql = 'SELECT * FROM images';
$result = $conn-&gt;query($sql) or die(mysqli_error()); //Line 5
$numRows = $result-&gt;num_rows;
</code></pre>

<p>Line 5 in this case refers to $result = $conn->query($sql) or die(mysqli_error());.
What Am I doing wrong here?</p>
