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

  • Home
  • SEARCH
  • 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 8428303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:00:58+00:00 2026-06-10T05:00:58+00:00

As far as I understood transaction starts once we call $mysqli->autocommit(FALSE); statement and ends

  • 0

As far as I understood transaction starts once we call $mysqli->autocommit(FALSE); statement and ends after calling $mysqli->commit(); command like in the example below.

<?php
//Start transaction 
$mysqli->autocommit(FALSE);
$mysqli->query('UPDATE `table` SET `col`=2');
$mysqli->query('UPDATE `table1` SET `col1`=3;');
$mysqli->commit();
//End transaction

//Executing other queries without transaction control
$mysqli->query("Select * from table1");
$mysqli->query("Update table1 set col1=2");
//End of executing other queries without transaction control

//Start transaction 
$mysqli->autocommit(FALSE);
$mysqli->query('UPDATE `table` SET `col`=2');
$mysqli->query('UPDATE `table1` SET `col1`=3;');
$mysqli->commit();
//End transaction
?>

Have I understood correctly? If not could you please correct me, because it is actually my first time using transactions in real life.

Thank you.

  • 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-10T05:01:00+00:00Added an answer on June 10, 2026 at 5:01 am

    Update Novembre 2020: @Dharman gave a better answer with more details about transactions in mysqli, just check it instead: https://stackoverflow.com/a/63764001/569101


    Well according to the php doc, you’re right.

    <?php
    $mysqli = new mysqli("localhost", "my_user", "my_password", "world");
    
    /* check connection */
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }
    
    $mysqli->query("CREATE TABLE Language LIKE CountryLanguage");
    
    /* set autocommit to off */
    $mysqli->autocommit(FALSE);
    
    /* Insert some values */
    $mysqli->query("INSERT INTO Language VALUES ('DEU', 'Bavarian', 'F', 11.2)");
    $mysqli->query("INSERT INTO Language VALUES ('DEU', 'Swabian', 'F', 9.4)");
    
    /* commit transaction */
    $mysqli->commit();
    
    /* drop table */
    $mysqli->query("DROP TABLE Language");
    
    /* close connection */
    $mysqli->close();
    ?>
    

    In the example above:

    • the CREATE TABLE is auto committed because it’s the default behaviour.
    • the INSERT INTO aren’t auto committed because of the autocommit(FALSE).
    • the DROP TABLE is auto committed because the autocommit(FALSE) was reset by the ->commit();.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As far as I understood the static initialization block is used to set values
As far as I understood it, BigInts are usually implemented in most programming languages
The TransactionScope expects a call to its Complete method as follows. Otherwise the transaction
As far as I understand it, each transaction sees its own version of the
As far as I understood it is not possible to rise privileges within the
I am new python programmer,what I have understood so far,yield keyword returns an object
I saw a field text[] (text array) in Postgresql. As far as I understood,it
As far as i understood, a string with an @ in required a set
As far as I understood DataSourceTransactionManager binds a JDBC connection from the specified DataSource
I've got a bug with UTF-8 normalizations: as far as I understood, there's (at

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.