Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7962559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:22:14+00:00 2026-06-04T05:22:14+00:00

I have a TRIGGER for a MySQL table which raises exception with SIGNAL when

  • 0

I have a TRIGGER for a MySQL table which raises exception with SIGNAL when there’s something wrong with the data provided. How can I catch this exception in PHP with PDO?

Thanks in advance.

UPDATE

More information on my problem: I am executing several queries within a transaction and I want to rollback the transaction if one of them fails because there was a SIGNAL. Currently a signal is activated but all the other queries are executed.

ANOTHER UPDATE

So far I’ve got:

try {
  $db->beginTransaction();

  if (!$db->query('UPDATE accounts SET amount = amount - 10 WHERE id = 1')) {
    throw new Exception($db->errorInfo()[2]);
  }

  if (!$db->query('UPDATE accounts SET amount = amount + 10 WHERE id = 2')) {
    throw new Exception($db->errorInfo()[2]);
  }

  $db->commit();
} catch (Exception $e) {
  $db->rollback();
  echo 'There was an error: ' . $e->getMessage();
}

Is this the proper way to do a transaction with handling the exceptions?
Sorry if my question is too broad.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:22:16+00:00Added an answer on June 4, 2026 at 5:22 am

    Try something like:

    $ls_error = "";
    $mysqli->autocommit(FALSE);
    // first sql
    if (!$mysqli->query($sql)) {
        $ls_error .= sprintf("Error: %d: %s\n",$mysqli->errno,  $mysqli->error);
        $mysqli->rollback();
    }
    // second one
    if ($ls_error == "") {
        if (!$mysqli->query($sql)) {
            $ls_error .= sprintf("Error: %d: %s\n",$mysqli->errno,  $mysqli->error);
            $mysqli->rollback();
        }
    }
    
    // third one
    if ($ls_error == "") {
        if (!$mysqli->query($sql)) {
            $ls_error .= sprintf("Error: %d: %s\n",$mysqli->errno,  $mysqli->error);
            $mysqli->rollback();
        }
    }
    if ($ls_error == "") {
        $mysqli->commit();
    } else {
        echo $ls_error;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this trigger which works functionally (as far as I can tell by
I have a mysql table which on any change (i.e. insert, update and delete)
I have a MySQL database which contains a table of users. The primary key
I have a mysql legacy table which contains an client identifier and a list
I have a mysql trigger that logs every time a specific table is updated.
I have MySQL table products , which has url and url_crc fields. I have
If I have a table in MySQL which represents a base class, and I
I have problem with creating a simple MySQL trigger in C#. I'm using StringBuilder
I have within my Sql Server 2008 database a trigger which will run on
I have a trigger that stores changes made in a separate table when a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.