I have the following code
public function actualizarLogin($idusuario, $usu_login=NULL,
$usu_passwd=NULL) {
$result=false;
try {
$db=new PDO(MYSQL_CON, MYSQL_USER, MYSQL_PASSWD,
array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
try {
$db->beginTransaction();
$sql="UPDATE usuario SET usu_login=?, usu_passwd=?
WHERE idusuario=?";
$pstmt=$db->prepare($sql);
$pstmt->bindParam(1, $usu_login, PDO::PARAM_STR);
if($usu_passwd==null) {
$pstmt->bindParam(2, $usu_passwd, PDO::PARAM_NULL);
} else {
$pstmt->bindParam(2, crypt($usu_passwd, CRYPT_MD5), PDO::PARAM_STR);
}
//Accidentaly using wrong variable here
$pstmt->bindParam(3, $usu_login, PDO::PARAM_INT);
$pstmt->execute();
//But commit return true and no Exception is thrown
$result=$db->commit();
} catch (PDOException $e) {
$result=$e->getMessage();
$db->rollBack();
throw new RPC_INTERNAL_ERROR();
}
}catch (PDOException $e) {
$result=$e->getMessage();
throw new RPC_INTERNAL_ERROR();
}
return $result;
the RPC_INTERNAL_ERROR
is an exception from zoservices, the library that I'm using for the JSON-RPC Server, and this method is called from a client.
As you can read the comments inside the code, I made a mistake, something very human, I'm using the wrong variable to bind the last parameter, and I'm telling to bind it as an integer while actually is string (it's the login instead of the id). But for some reason even when I'm telling to throw an exception on failure there is no such exception, but the worst of all is that commit return true... Why? I spent a precious time just to find that error, because PDO wasn't telling me nothing about that. There is any way to handle those mistakes?