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 6928231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:09:34+00:00 2026-05-27T11:09:34+00:00

How can I do multiple queries, the usen commit(), and if something goes wrong,

  • 0

How can I do multiple queries, the usen commit(), and if something goes wrong, rollback all queries?

I noticed that if I wrap my queries and commit with inside try / catch, only the unsuccesful queries are rolled back

try{

  $pdo->beginTransaction();

  // create 10 tables
  foreach($queries as $query)
    $result = $pdo->query($query);

  $pdo->commit();

}catch(PDOException $e){

  // here if one of the tables fail to be created, undo all operations
  $pdo->rollBack();  

}
  • 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-05-27T11:09:35+00:00Added an answer on May 27, 2026 at 11:09 am

    MySQL does not support embedded transactions.

    If you think you are getting a partial rollback, you are checking it wrong. In particular, an unsuccesful query will not even run, so there’s nothing to rollback there. What happens is that you don’t really have a transaction, either because you forgot the START TRANSACTION statement or because your tables are not InnoDB.

    Edit: I’ve just seen you’ve updated your question. You cannot rollback DDL statements such as CREATE TABLE. You can only rollback DML statements (SELECT, INSERT, UPDATE…). This is not a MySQL limitation, it’s the standard behaviour in all DBMS engines I know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can i make multiple, composite query in oracle? for example this several queries
DocumentsController#common_query can handle multiple different request styles. i.e. all docs in batch 4 or
I know that you can insert multiple rows at once, is there a way
I know that I can insert multiple rows using a single statement, if I
I make multiple queries to my DB from my python code that uses pyodbc
Can the same mysql resource be used for multiple queries? $queries=array($q1, $q2); $link=mysql_connect(...); mysql_select_db(...);
I want to execute multiple queries asynchronously. Now for that I have searched but
Just wondering if any Firebird users can confirm that batched queries is not a
I currently have a website written in classic asp that runs multiple queries against
Can multiple SSRS share the same DB? We're getting into an SSRS customization scenario,

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.