Reply to Using transactions in MySQL + PHP

Your name:

Reply:


Posted by Joγo Morais on 08/01/07 12:44

Hi there guys,

My doubt is related with MySQL and Transactions (InnoDB) so here it
goes:

I have a query like this:

$query = 'START TRANSACTION; ';
$query .= 'UPDATE sections ';
$query .= 'SET position=position-%d ';
$query .= 'WHERE position > %d; ';
$query .= 'DELETE FROM sections ';
$query .= 'WHERE id IN %s; ';
$query .= 'COMMIT;';

$result = $db->query(sprintf($query, count($id), $db-
>result($result), $ids));

This will perform a query similar to this one:

START TRANSACTION; UPDATE sections SET position=position-2 WHERE
position > 1; DELETE FROM sections WHERE id IN (15,16); COMMIT;

If I var_dimp $result I will get: bool(false)

So query failed, my doubt is why?

If I copy-paste it and type it on MySQL console or PHPMyAdmin, it will
run with no problems.

Also If I separate $query in four queries, and run them separately,
the script will run too.

Can't this be done like this? If so, what is the correct way of doing
it?

This are maybe simple questions, but thats the first time Im using
transactions, and I didn't found much info on this.

PS: My database is running, and has some data in it.

Thanks for your attention.

[Back to original 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

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