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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:03:58+00:00 2026-06-03T11:03:58+00:00

Can function calls occur within a PDO transaction block? This is simplified code (using

  • 0

Can function calls occur within a PDO transaction block? This is simplified code (using MySql database)…

try{  
  $db->beginTransaction();  

  // call to function that creates user
  $user_id = create_user();  

  // call to function that creates company      
  $company_id = create_company();

  // call to function to link user & company
  add_user_to_company($user_id, $company_id);

  $db->commit();  
}

If this can’t happen using transactions, what is the recommended strategy?

  • 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-03T11:03:59+00:00Added an answer on June 3, 2026 at 11:03 am

    Unless any of those function calls attempts to open or commit a transaction themselves, or use a different connection than the one stored in $db, yes it should work just fine.
    The PDO object (or the RDBMS for that matter) doesn’t know or care whether you are calling other functions in PHP. All it knows is if the action is taking place on the same open connection as the one opened in $db. We assume that those functions either receive $db as a parameter or access it globally.

    Remember that although PDO keeps track of transaction state (exposed through PDO::inTransaction()), it is really the RDBMS which is managing the transaction state, not PDO or the PHP application code. If, a function attempts to open a new transaction before the previous one was committed, MySQL’s documented behavior is to auto-commit the previous transaction since it does not support transaction nesting.

    So just be sure your additional function calls are not attempting to change the transaction state.

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

Sidebar

Related Questions

I have a jButton that calls a function. This function can take up to
I have a block of code that runs within a TransactionScope and within this
This situation can only occur without name mangling (I believe), so the below code
In android, How can I repeat calls a function from the time user press
How can I wrap a recursive function, recursive calls included? For example, given foo
I'm using the following ajax function: function callAjax(request,callback) { if (window.XMLHttpRequest) {// code for
I am using the following function within a WndProc override: Public Function GetPortName() As
I recently discovered that in C++ you can overload the function call operator, in
I would like to have a function that can wrap any other function call.
How can i skip first argument without giving any value in function call,so that

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.