PDO doesn’t throw an error in case of a trigger error

Have trigger on table with DELETE event. And special have and error in this. When delete row manually receive an error, but when trying to delete via PDO, receive success statement, and row successfully delete. Don't understand where problem.

Trigger code

CREATE DEFINER=`user` TRIGGER `TR_VM_users_AD` AFTER DELETE ON `VM_users` FOR EACH ROW BEGIN
    /* Archive profile */   
    INSERT INTO VM_users_archive (date_time_created, date_time_modified, imsi, msisdn, `password`, skip_password, email, send_email, is_header_enabled, ivr_lang, sms_lang, ussd_lang, status_id)
    VALUES (OLD.date_time_created, OLD.date_time_modified, OLD.imsi, OLD.msisdn, OLD.`password`, OLD.skip_password, OLD.email, OLD.send_email, OLD.is_header_enabled, OLD.ivr_lang, OLD.sms_lang, OLD.ussd_lang, OLD.status_id);
    
        /* Delete personal blacklist */
        DELETE FROM VM_personal_blacklist WHERE callednumber = OLD.msisdn;
        
        /*Delete greetings */
        DELETE FROM VM_greetings WHERE called_number = OLD.msisdn;
END;

MYSQL error when trying to delete manually

mysql> Delete from VM_users where msisdn = 810044168;
ERROR 1054 (42S22): Unknown column 'callednumber' in 'where clause'
mysql>

php code

try
{
    $transactionStartTime = microtime(true);
    
    $this->db->pdo->beginTransaction();
    
    $queryDeleteProfile = 'DELETE FROM VM_users WHERE msisdn = :msisdn';
    
    if (!$this->db->preparedQuery($queryDeleteProfile, ['msisdn' => $msisdn]))
    {
        $this->db->pdo->rollBack();
        
        return false;
    }
    
    $this->db->pdo->commit();
    
    $transactionEndTime = round((microtime(true) - $transactionStartTime), 2);
    
    $this->utility->loggerAll($this->logPrefix, __FUNCTION__, $this->logLevel, 3, 'Profile deleted. msisdn: ' . $msisdn . ', transactionEndTime: ' . $transactionEndTime);  
}
catch (\PDOException $ex)
{
    $this->utility->loggerAll($this->logPrefix, __FUNCTION__, $this->logLevel, 1, 'Failed to delete profile!. msisdn: ' . $msisdn . ', errorMessage: ' . $ex->getMessage());
    
    $this->db->pdo->rollBack();
    
    return false;
}

public function preparedQuery($query, $params)
{
    try
    {
        $this->checkConnection();
        $stmt = $this->pdo->prepare($query);
        
        if (!$stmt->execute($params))
        {
            $this->utility->loggerAll($this->logPrefix, __FUNCTION__, $this->logLevel, 1, 'Failed to execute prepared query! ' . $this->pdo->errorInfo()[2] . ', query: ' . $query . ', params: ' . json_encode($params));
            
            return false;
        }
    }
    catch (PDOException $e)
    {
        $this->utility->loggerAll($this->logPrefix, __FUNCTION__, $this->logLevel, 1, 'Failed to execute prepared query! ' . $e->getMessage() . ', query: ' . $query . ', params: ' . json_encode($params));
        
        return false;
    }
    
    return $stmt;
}


Read more here: https://stackoverflow.com/questions/65700682/pdo-doesnt-throw-an-error-in-case-of-a-trigger-error

Content Attribution

This content was originally published by quaresma89 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: