savepoint within PHP script<

liunx

Guest
Hi I an trying to use the mysql SAVEPOINT savepoint_name, ROLLBACK, COMMIT within a PHP script. I have tried enclosing in "" but that didn't work have tried not enclosing that didn't work. The idea is if any of the 3 update queries fall over then rollback and remove all updates but that aint happening Any help appreciated.

BobNZ

I have:

AUTOCOMMIT=1
SAVEPOINT s1
BEGIN

some php and update 1

if(!$result)
ROLLBACK TO SAVEPOINT s1
else

some php and update 2

if(!$result)
ROLLBACK TO SAVEPOINT s1
else

some php and update 2

if(!$result)
ROLLBACK TO SAVEPOINT s1
else

COMMIT:confused:what exactly is the code? what you have there will not work because you forgot a lot of stuff.

BEGIN;
SELECT * FROM table1 WHERE type=1;
UPDATE table2 SET summmary='A' WHERE type=1;
COMMIT;

you have to use mysql_query to do this. so that is why your code is incomplete.Its OK I got it to work. What I showed was pseudo code not the actual code. I had created functions for begin, rollback, commit so I needed to set autocommit to "0". If I had of just used 'BEGIN' etc outside of a function then autocommit would have been set to "0" automatically and everthing would have worked :)
With mysql 4 onward you can create savepoints to rollback to; I was interested to see if anyone had used that.

BobNZ
 
Back
Top