|
Posted by Joγo Morais on 08/01/07 20:24
First, thanks to all for your answers.
Second, lets see..
$query1 = 'START TRANSACTION';
$result1 = $db->query($query1);
if (!$result1) die("transaction failed at step1");
$query2 = 'UPDATE sections SET position=position-%d WHERE position >
%d';
$result2 = $db->query(sprintf($query2, count($id), $db-
>result($result)));
if (!$result2) die("transaction failed at step2");
$query3 = 'DELETE FROM sections WHERE id IN %s';
$result3 = $db->query(sprintf($query3, $ids));
if (!$result3) die("transaction failed at step3");
$query4 = 'COMMIT';
$result4 = $db->query($query4);
if (!$result4) die("transaction failed at step4");
echo 'Done...';
Logic, split main query into 4 queries.
Check one by one if they are made with success, if so proceed,
otherwise report failure.
Since data will only be saved if COMMIT is done, shoud step4 be like
the one above? If one of the first 3 steps fail, script will be
aborted and no data will be commited.
Im not sure this is the right way to use commit/rollback .. any ideias/
comments on this will be appreciated.
Thanks in advance guys.
Navigation:
[Reply to this message]
|