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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:05:12+00:00 2026-05-31T18:05:12+00:00

I am having a strange problem which I don’t understand. I have the following

  • 0

I am having a strange problem which I don’t understand. I have the following function which is supposed to return $asset_ID:

function commit_purchase($asset_type_ID, $org_ID, $asset_desc, $asset_cost, $date, $org_to_member_ID, $asset_ID, $purchaser_cur_invest, $purchaser_cred_deb, $purchaser_balance) {
global $db;
$db->beginTransaction();
$query = "INSERT INTO assets
                       (asset_type_ID, org_ID, asset_desc, asset_cost, asset_value, purchase_date, is_approved)
                    VALUES
                       (:asset_type_ID, :org_ID, :asset_desc, :asset_cost, :asset_cost, :date, 1)";
$statement = $db->prepare($query);
$statement->bindValue(':asset_type_ID', $asset_type_ID);
$statement->bindValue(':org_ID', $org_ID);
$statement->bindValue(':asset_desc', $asset_desc);
$statement->bindValue(':asset_cost', $asset_cost);
$statement->bindValue(':date', $date);
$statement->execute();
$asset_ID = $db->lastInsertId();
//return $asset_ID;
$db->commit(); 
}

I am calling the function like so:

$asset_ID = commit_purchase($asset_type_ID, $org_ID..etc, etc.);

If I uncomment the return $asset_ID, the transaction rolls back and does not commit. If I leave it commented, the variable is not passed. If I comment out the beginTransaction and commit lines, I can uncomment the return $asset_ID and everything works.

I want it to stay as a transaction and I want to return the $asset_ID. What am I doing wrong?

  • 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-31T18:05:13+00:00Added an answer on May 31, 2026 at 6:05 pm

    You need to move the return $asset_ID; line to after the commit as the execution of the function stops when you return. Without the commit being called you get an implicit rollback.

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

Sidebar

Related Questions

I am having a strange problem. I have a function which returns a large
I seem to be having a strange problem which I can't fully understand. This
I'm having a strange problem with php PDO and mysql. I have the following
I'm having a strange problem. I've got a function dbo.ufn_GetDaysInYear which seems to give
I'm having a strange problem. I have to use GetPostBackEventRefence to force a Postback,
I'm having a strange problem here... I have an ASP.NET 3.5 application that has
i am having a strange problem, i have a static class like this public
I'm having a strange problem in that I have php inserting text into a
Im having a very strange problem, i have a complicated view that returns incorrect
I'm having a strange problem with a colour animation. I have a list of

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.