birbal Posted September 11, 2013 Share Posted September 11, 2013 I prefer to set error mode to Exception and catch that on failure. Link to comment Share on other sites More sharing options...
jimfog Posted September 11, 2013 Author Share Posted September 11, 2013 That doesn't matter, mysqli::query also returns false if a query fails, right? So you think $all_query_ok=true; is redundant? Link to comment Share on other sites More sharing options...
justsomeguy Posted September 11, 2013 Share Posted September 11, 2013 I wasn't suggesting that, I was just suggesting that whether you are using PDO or mysqli is irrelevant for the example in post 23. You can use a variable to keep track of whether or not there were any errors, or you can just test each result to find out. It doesn't matter if you're using PDO or mysqli. Link to comment Share on other sites More sharing options...
jimfog Posted September 11, 2013 Author Share Posted September 11, 2013 Ι think this code must be OK now...I am going to test it either way: $connection->autocommit(FALSE); $result1 =$connection->query("insert into users values (NULL,'" .$name. "','" .$lastname . "','".$email."','". $passwd."','". $hash."','4')"); $result2=$connection->query("insert into business_users values('".$connection->insert_id."','".$address."' , '".$url ."','".$phone. "','".$city. "','".$municipality. "','".$buztype. "')"); if(!$result||!$result2) {$connection->rollback(); $connection->autocommit(TRUE); echo 'transaction failed'; return false; } else { $connection->commit(); $connection->autocommit(TRUE); } Link to comment Share on other sites More sharing options...
jimfog Posted September 12, 2013 Author Share Posted September 12, 2013 After the queries are finished, should I always use autocommit(TRUE)? Or the commit method is sufficient to turn on again the autocommit feature of the db? It is not clear to me. Provided the fact of course that I do want to set it that way. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 12, 2013 Share Posted September 12, 2013 I don't see anything in the documentation which would suggest that using the commit method has any effect on the autocommit setting. It would be easy enough to test for yourself though. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now