SpankMarvin Posted February 15, 2010 Share Posted February 15, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/192180-necessary-to-restore-autocommit-on-return-false/ Share on other sites More sharing options...
SpankMarvin Posted February 15, 2010 Author Share Posted February 15, 2010 Ahem, got dollar-happy. Of course, the return false should be without the $. Still interested in the necessity of the autocommit declaration though. J Quote Link to comment https://forums.phpfreaks.com/topic/192180-necessary-to-restore-autocommit-on-return-false/#findComment-1012805 Share on other sites More sharing options...
Mchl Posted February 15, 2010 Share Posted February 15, 2010 Better safe than sorry. You will certainly not break anything by setting it to on. Check this in manual to be sure, but I think autocommit stays disabled after a commit. Quote Link to comment https://forums.phpfreaks.com/topic/192180-necessary-to-restore-autocommit-on-return-false/#findComment-1012807 Share on other sites More sharing options...
SpankMarvin Posted February 15, 2010 Author Share Posted February 15, 2010 Thank you! Yes, I thought this would not be a bad thing to do, but wanted to check! Thanks for your response. J Quote Link to comment https://forums.phpfreaks.com/topic/192180-necessary-to-restore-autocommit-on-return-false/#findComment-1012827 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.