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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:45:39+00:00 2026-05-13T20:45:39+00:00

I have code that looks like this: function foobar(array& $objects, $con = null) {

  • 0

I have code that looks like this:

function foobar(array& $objects, $con = null)
{
   if (is_null($con))
      $con = DbSingleton::getConnectio();

   $con->beginTransaction();  // <- question 1

   try
   {
     foreach($objects as $object)
     {
        // allocate memory for new object 
        $new_obj = new MyShiningNewObject();

        // do something to the new object ...
        $new_obj->setParentId($object->getId());
        $new_obj->save($con);

        // mark for garbage collection
        unset($new_obj);  // <- question 2
      }

     $con->commit();
  }
  catch(Exception $e){ $con->rollBack(); }      
}

My questions are:

  1. I am begining a transaction, this could well be a nested transaction. In the case of a nested transaction, if an exception is thrown and I rollback, how far back does the rollback go (to the outermost transaction) – common sense suggest that this should be the case, but one never knows.

  2. I am freeing memory (ok, marking as ‘freeable’ by the Zend GC). Since I am commiting the transaction AFTER the loop, (the variable is marked as frreable IN the loop), is this safe – I mean will the data be safely stored in the db even though I have unset the variable that the value came from?

  • 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-13T20:45:39+00:00Added an answer on May 13, 2026 at 8:45 pm

    To answer question 2 :

    • once the query has been sent to the database, what is done on PHP variables doesn’t matter anymore
    • the only thing you’ll do that will have an impact is when you’ll commit or rollback.
    • which means that unsetting the PHP variable will have no impact on the transactions/data on the DB side.

    About question 1 :

    • If your database system supports nested transactions, commiting/rollbacking on an “inner” transaction should, logically, only act on that “inner” transaction.
    • But note that nested transactions are not supported by all DBMS — MySQL, for instance, doesn’t support them, as far as I remember.
    • For reference, here are three questions about nested reference (there are probably many more) :
      • Nested transactions in postgresql 8.2?
      • Nested transactions in Sql Server
      • Are nested transactions allowed in MySQL?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 320k
  • Answers 320k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to do the following steps Change document.getElementById("myImage") to… May 14, 2026 at 12:27 am
  • Editorial Team
    Editorial Team added an answer You need to subscride second combobox on the SelectedIndexChanged event… May 14, 2026 at 12:27 am
  • Editorial Team
    Editorial Team added an answer Start by learning about SIP protocol. If you don't want… May 14, 2026 at 12:27 am

Related Questions

After programming in C for several years, I realized that I have been ignoring
I'm trying to fix something in some Objective C++ (?!) code. I don't know
Taking the jQuery framework for example, if you run code like this: $(document).ready(function init()
As part of a project I have assigned myself as a way of improving
I have some XML code that looks like this <SEARCHRESULTS> <FUNCTION name=BarGraph> <PARAMETER name=numList></PARAMETER>

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.