jeudi 30 avril 2015

PDO won't return results from a SQLite database, or any exceptions

So I have a bit of code that I just cannot figure out. I have error reporting turned on, and I have the appropriate try/catch blocks, but the code below is not functioning. When I run this code, all I get is bool(false) from the var_dump($result).

try
{
    $db = new PDO('sqlite:norming_database.db');
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
    echo $e->getMessage();
}

/*... some other stuff in between ...*/

try
{
    $query = "SELECT stimulusName
            FROM responses
            WHERE workerId LIKE :workerId";
    $stmt = $db->prepare($query);
    $stmt->bindParam(':workerId', $_GET['testWorkerId']);
    $stmt->execute();
    $result = $stmt->fetch();
}
catch(PDOException $e)
{
    echo "PDO Error: " . $e->getMessage();
}

echo "<pre>" . var_dump($result) . "</pre>";

I'm getting no exceptions or errors. On top of that, if I run the query itself in my database manager (Valentia Studio), it returns exactly the result I'm expecting.

I suspect that there's some typo or something in my code that I'm failing to see after reading over it repeatedly. Is there anything blatantly wrong with how this is written?

Aucun commentaire:

Enregistrer un commentaire