Re: Using transactions in MySQL + PHP
- From: "João Morais" <jcsmorais@xxxxxxxxx>
- Date: Wed, 01 Aug 2007 20:24:54 -0000
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.
.
- Follow-Ups:
- Re: Using transactions in MySQL + PHP
- From: Jerry Stuckle
- Re: Using transactions in MySQL + PHP
- References:
- Using transactions in MySQL + PHP
- From: João Morais
- Re: Using transactions in MySQL + PHP
- From: Jerry Stuckle
- Re: Using transactions in MySQL + PHP
- From: ELINTPimp
- Using transactions in MySQL + PHP
- Prev by Date: Re: Uploading one file works, but uploading two results in 'Connection Interrupted'
- Next by Date: Re: only list dirs if they have jpgs inside
- Previous by thread: Re: Using transactions in MySQL + PHP
- Next by thread: Re: Using transactions in MySQL + PHP
- Index(es):
Relevant Pages
|