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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:24:26+00:00 2026-05-20T18:24:26+00:00

Is there a way to do transactions with prepared statements? I mean can I

  • 0

Is there a way to do transactions with prepared statements?

I mean can I use the following example with $mysqli->autocommit(FALSE); and $mysqli->commit( ); and $mysqli->rollback( );

//Preparing the statment

$insert_stmt=$mysqli->prepare("INSERT INTO x VALUES(?,?)")
or die($mysqli->error);

//associate variables with the input parameters

$insert_stmt->bind_param("is", $my_number,$my_string); //i=integer

//Execute the statement multiple times....

for ($my_number = 1; $my_number <= 10; $my_number++) 
{
    $my_string="row ".$my_number;
    $insert_stmt->execute() or die ($insert_stmt->error);
}
$insert_stmt->close();

I have looked around but can’t find any example of using prepared statements (not PDO):
http://php.net/manual/en/mysqli.prepare.php with transactions, I only find examples like these mentioned here: http://book.opensourceproject.org.cn/lamp/mysql/mysqlstored/opensource/0596100892/mysqlspp-chp-13-sect-2.html where transactions and prepared statements are never inter-mixed.

Would it be wrong to use them together?

  • 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-20T18:24:27+00:00Added an answer on May 20, 2026 at 6:24 pm

    Prepared statements and transactions are unrelated techniques and technologies.

    You may wish to issue the START TRANSACTION and COMMIT/ROLLBACK commands directly instead of using the dedicated methods. They are functionally equivalent.

    For your loop, you’d issue the START TRANSACTION before your prepare, then your COMMIT after the loop exits. You probably should not try to open a transaction after a prepared statement has been started but before it’s been executed.

    For some reason, they didn’t add a “start transaction” command in favor of turning off autocommit. It’s one of those weird things about mysqli that makes me always recommend PDO instead. 🙂 Opening a transaction implicitly turns off autocommit for the duration of the transaction.

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

Sidebar

Related Questions

Is there a way to implement something like COMMIT transactions of RDBMSs in R
Is there a way one EntityManager can participate smoothely in multiple concurrent transactions? Well,
Is there any way transactions can be implemented in .Net web services ?. Is
Is there way that I can read the file from remote server using fopen
Nowadays, Prepared statements seem to be the only way anyone recommends sending queries to
I configured spring with transactional support. Is there any way to log transactions just
Is there any way to make microsoft access transactions atomic across multiple users? I
Since MongoDB does not support transactions, is there any way to guarantee transaction?
Is there a way to implement transactions in code first without having to write
Is there a way to manually specify transactions in symfony2 with the entity manager

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.