Jump to content

Recommended Posts

Hi all

 

I am running a query that loops through an array of id numbers for a given table. Basically the user would have selected one or several rows in a table that I have outputted, and the script goes through each id number and deletes that entry from the corresponding SQL table.

 

In order to do this, I am turning OFF autocommit so I get all or nothing -- either all the selected records are deleted, or nothing is changed in the event of an error.

 

Within my foreach loop that references the array of id numbers, I have the following:

 

foreach($deletions as $action){
	$query = "delete from my_table where id='".$action."'";
	$result = $conn->query($query);
	if(!$result){
		$return false;
	}
}

Following this loop, I commit the changes, and switch autocommit back to TRUE before returning true.

 

My long-winded question is, do I need to add an "$conn->autocommit(TRUE);" line before the "return false" line? Will the autocommit remain OFF if I do not do this and an error quits the function? Or, to put it another way, am I in any way interrupting the autocommit setting by adding this? It seems like it ought to be harmless, but I wanted to check!

 

Thanks

 

J

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.