But if there is an error in the "SELECT" query (either syntax error, or
reference to missing table), then no exception is raised, and control
just continues in the try block with a null result from the query.
Is this the intended behaviour?

Hey, it's really fun I was looking here and on internals to ask quite the same thing.

In fact what I have found is that PDO error default handler is silent. But you can change it using :



// Connexion parameter
$user = 'cyril';
$pass = 'motdepasse';
$dsn = 'mysql:host=localhost;dbname=testPDO';

// Connexion
try {
   $dbh = new PDO($dsn, $user, $pass);
} catch (PDOException $e) {
print "Erreur ! : " . $e->getMessage() . "<br/>";


try {

        $sql = "INSERT INTO produit (idproduit, nom, marque, prix)
        VALUES (NULL,'CB500', 'Honda', '6000')";
        $idInsere = $dbh->lastInsertId();
        $sql2 = "INSERT INTO disponibilite (idproduit, quantite)
        VALUES ('$idInsere', 5)";

}catch (PDOException $e){
        print "Erreur ! : " . $e->getMessage() . "<br/>";


PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to