Q:

execute method is always set to true

I have a problem with a php script.
I want to delete a record from my database so I used the execute() method, and it should return false when there is no record with the code I pass as an argument, but it always return true despite of there is not any record with that code.
This is the script:
<?php

include('connexion.php');

//Récuperation des valeurs 
$code = $_POST['code'];

if($code)
{
    //Suppression de l'enregistrment avec le code = $code à m'aide d'une requête préparée
    $req = $bdd->prepare('Delete from chambre where code_ch = ?');
    $rowDeleted = $req->execute(array($code));
    //Ou bien : mysql_query('Delete from chambre where code_ch = '.$code);

    $supprimer = ($rowDeleted == true) ? 'OK' : 'notfound';

}
else
{
    $supprimer = 'empty';
}

header('Location: supprimer.php?supprimer='.$supprimer.'&code='.$code);

?>

A:

A PHP PDO object will (correctly) return a success/true value for deletion on ZERO rows. One way around this is to use something like $pdo->rowCount() to see how many rows the PDO affected. If you are trying to remove rows, you should consider a result of 0 from $pdo->rowCount() to mean that you did not successfully delete the row you wanted to.

