Ok, second post for the PHP5 board today. This one, I've tested and recreated a small example, so I'm pretty sure I need help with this one :p
When I execute the following Code, I would expect no changed to be made to the database and the transaction to be rolled back. Why isn't it?
The table is simple, has two collums, first is an int, second a varchar.
<?php
header("Content-type: text/plain");
$test = new PDO("mysql:host=localhost;dbname=gmac", "root", "", array(PDO::ATTR_PERSISTENT => true));
$test->beginTransaction();
try{
$test->query("TRUNCATE Area;");
$id = rand(0, 100);
$test->query("INSERT INTO Area VALUES ($id, 'Edinburgh');");
throw new Exception("failed");
$test->commit();
echo "commited";
} catch (Exception $e){
$test->rollBack();
echo "rolled back\n" . $e->getMessage();
}
My first instinct is to call BUG, but I know there is probably something I'm overlooking. If I had another server set up I'd try another DBMS.
Ok, my last sentence triggered me to check the mySQL bug tracker and I found this : http://bugs.mysql.com/bug.php?id=8151
So, truncate table cannot be rolled back. How can I get around this otherwise? I imagine "DELETE FROM Area" would be pretty slow...