Here's how we can do it:
<?php
function addShop($shop){
$ok = true;
$ok = $ok && mysql_query('START TRANSACTION');
$ok = $ok && shops_AddShop($shop);
$ok = $ok && ($shop['id'] = mysql_insert_id());
$ok = $ok && shops_UpdateCategories($shop);
if($ok){
mysql_query('COMMIT');
}else{
mysql_query('ROLLBACK');
}
return $ok;
}
?>If one of the MySQL queries failed, I can do a rollback and reverse the appropriate changes. It's much better taking advantage of the short circuit evaluation as talked about earlier on.
In that case you will have a more stable application.


No comments:
Post a Comment