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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:29:47+00:00 2026-05-17T21:29:47+00:00

Been scratching my head on this for a while…. I have a PDO object

  • 0

Been scratching my head on this for a while….

I have a PDO object with pdo->setAttribute(PDO::ATTR_AUTOCOMMIT,0); as I want to use FOR UPDATE with some InnoDB tables. Reading the MySQL documentation, FOR UPDATE will only lock read rows if:

  1. You are in a transaction
  2. You are not in a transaction and set autocommit=0 has been issued

So, I am using ATTR_AUTOCOMMIT to allow the PDO object to lock rows. In either case, this is causing INSERT and UPDATE statements to not apply. These statements are nothing to do with FOR UPDATE they are just running through the same PDO object with prepared statements.

My MySQL query log looks like:

xxx    Connect   user@host
xxx    Query     set autocommit=0
xxx    Query     INSERT INTO foo_tbl (bar, baz) VALUES ('hello','world')
xxx    Quit

PHP/PDO doesn’t complain, but selecting from the table shows that the data hasn’t been written.

The queries that I am running have been run thousands of time prior; only the ATTR_AUTOCOMMIT change has been made. Removing that option makes everything work again. Transactions are working fine with the option autocommit=0 too.

Are there additional calls that need making on the PDO object (commit() complains rightly that it isn’t in a transaction) to make the changes stick? Basically, I want a plain PDO object but with the option to lock rows outside of transactions for InnoDB tables (the background to why is too long and boring for here).

I’m sure this is something stupid I am missing scratches head

  • 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-17T21:29:48+00:00Added an answer on May 17, 2026 at 9:29 pm
        $db = new PDO('mysql:dbname=test');
        $db->setAttribute(PDO::ATTR_AUTOCOMMIT,0);
        var_dump($db->query('SELECT @@autocommit')->fetchAll()); //OK
        $db->query("INSERT INTO foo (bar) VALUES ('a');");
        $db->query("COMMIT;");//do by SQL rather then by interface / PDO-method
    

    But essentially, you’re in a transaction (you just haven’t started it with PDO), a rollback etc. is also still available. It’s quite debatable whether this is a bug (not being able to call commit() directly).

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

Sidebar

Related Questions

I have been scratching my head on this for a while now but still
I have been scratching my head for a while on this one. I dont
I've been scratching my head on this one for a while now and am
I have been scratching my head over this for days and I still cannot
I've been scratching my head for quite some time now, this code worked fine
I've been scratching my head for several hours for this... problem: Binary Tree (0)
I've been scratching my head over this for over a week now and haven't
Been a while since I've dealt with ASP.NET and this is the first time
I am scratching my head over for this issue for last few weeks. My
i have this problem that has been buggin me for the last hours. Lets

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.