So far when it comes error handling with queries in a function I follow the following logic:
$result1 = $connection->query("insert into users values (NULL,'" .$name. "','" .$lastname . "','".$email."','". $passwd."','". $hash."','". $usertype."')"); if (!$result1) { throw new Exception('error'); } else{$result2=$connection->query("insert into business_users values ('".$connection->insert_id."','" .$address."','".$url ."','".$phone. "','".$city. "','".$municipality. "','".$buztype. "')"); } if(!$result2) { throw new Exception('error'); return false;}
The problem with the above flow is that the first query might finish successfully while the second might not.
The goal is that if one of them fails the other should not run at all...more specifically I do not want the the first query running if the second fails, something which the above code fails to do.
Even if the 2nd insertion fails the 1st will be performed.
I do not want partial entries in the DB...what control structure I should follow so that both insertions take place or none of them.