Jump to content

Necessary to restore autocommit on return false?


SpankMarvin

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.