try {
$query = 'UPDATE keywords SET value = :keyvalue WHERE keyword = :keyname AND document_id = :docId';
$pdo = _openConnection();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->beginTransaction();
$pdoStatement = $pdo->prepare($query);
foreach ($keywords as $keyname => $keyval) {
$pdoStatement->bindParam(':docId', $id, PDO::PARAM_STR);
$pdoStatement->bindParam(':keyname', $keyname, PDO::PARAM_STR);
$pdoStatement->bindParam(':keyvalue', $keyval, PDO::PARAM_STR);
$pdoStatement->execute();
}
$res = $pdo->commit();
var_dump('retornando true', $res);
return true;
} catch (PDOException $e) {
$pdo->rollBack();
echo $e->getMessage();
return false;
}
The sentence updates a given row identified by KEYWORDNAME
and DOCUMENT_ID
.
I am sending a wrong keyword name (non-existent) but existent document id.
Shouldn't it throw an exception for record not found and rollback the operation? It is always succeeding and returning true (also I see the var_dump)
PS: this is the last portion of the code.