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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:09:16+00:00 2026-05-26T01:09:16+00:00

I was reading about mysql transactions and I was under the impression that you

  • 0

I was reading about mysql transactions and I was under the impression that you had to use either mysqli or PDO in order to create transactions. However, I see all over stack exchange and other sites examples that use the mysql extension like this:

mysql_query("START TRANSACTION");
$rollback=0

if (!mysql_query($query1)){
$rollback=1
}

if (!mysql_query($query2)){
$rollback=1
}

if (!mysql_query($query3)){
$rollback=1
}

if ($rollback == 1){
mysql_query("ROLLBACK");
}
else{
mysql_query("COMMIT");
}

What is the difference between doing it this way and using the “special” mysqli specific functions mysqli::rollback and mysqli::commit?

Also, what happens if the php script crashes (IE my app server crashes etc), does the DB server automatically rollback the transaction after a set timeperiod?

Similarly, what happens if the DB server crashes before mysql_query(“COMMIT”)? Would the transaction be “rolled back”?

Thanks!

  • 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-26T01:09:17+00:00Added an answer on May 26, 2026 at 1:09 am

    It’s also perfectly legal and is using MySQL statements directly to implement transaction.

    And frankly, I don’t see any improvements by using the mysqli syntax. It’s a failed abstraction since it maps 1:1 on MySQL only. It would make more sense to use the higher level syntax in PDO, since it will map with a different syntax according to the underlying DB.

    However, as Hakre says: mysqli is preferred for performance and interoperability reasons, it's the recommended mysql lib in PHP.

    Similarly, what happens if the DB server crashes before mysql_query("COMMIT")? Would the transaction be "rolled back"?

    It’s easier that an application program crashes rather than a DB server. Any non committed transaction will be rolled back.

    Also a transaction can be rolled back because it can’t acquire a lock within a certain timeout.

    The timeout in seconds an InnoDB transaction may wait for a row lock before giving up. The default value is 50 seconds. A transaction that tries to access a row that is locked by another InnoDB transaction will hang for at most this many seconds before issuing the following error:

    ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

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

Sidebar

Related Questions

Reading about Django, I saw this: http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#ref-contrib-admin - the fancy simple to use admin
Reading about Delphi's Exit statement (see here for instance), I cannot ignore that writing
When reading about pipes in Advanced Programming in the UNIX Environment, I noticed that
Was just reading about different algos disassemblers use to identify binary as assembly instructions.
So after reading Performance in PDO / PHP / MySQL: transaction versus direct execution
I am reading a manual about innodb transactions but still, there is lots of
Last night I was reading about a mysql tuning program here. I installed it
I've been reading a bit about Prepared statements with MySql, and the .NET/Connector does
I'm reading very detailed tutorials on how to use transactions with database types and
I am reading about SOLR and indexing a MySQL database into SOLR. What do

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.