You are here: Re: Using transactions in MySQL + PHP « PHP Programming Language « IT news, forums, messages
Re: Using transactions in MySQL + PHP

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]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация