|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
PHP-General - Undo MySQL Queries
Hi,
If you have many mysql update/insert/delete queries in a page how do you make sure they are all not executed if one of them fails. E.g. You have mysql queries.. insert update insert insert insert insert update What if the 4th query fails for some reason, e.g. timeout, server crash, is there a way to make the first 3 queries "undo". I know you can do mysql_affected_rows() and die() if the queries fail and the subsequest queries will not run but is there a way to affect the queries run before that? Thanks.
__________________
"They have the internet on computers now" - Homer |
|
#2
|
|||
|
|||
|
I think for that you'd need transactions, and that would require tables to be all innodb.
__________________
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer" - Bruce Graham |
|
#3
|
|||
|
|||
|
As simon said, look into transactions.
Basically, before all your queries are run, you start a transaction. What happens within the transaction can be looked at like a 'dry run' or a 'cache'. You can see the results, but they havent been properly applied. If there is an error, the transaction automatically rolls back, otherwise you can try to catch an error and rollback yourself. If all goes well, you can commit the transaction to make the changes final. clicky
__________________
Regards, Christian Biggins - Blogger Extraordinaire | Skylines Australia Owner | PHPOnIn Developer* | Good Question Asker Appreciater * Work in Progress. Scheduled Version 1.0 release 01/04/2008
|
|
#4
|
|||
|
|||
|
Thanks, much to read. Have any of you guys implemented this?
|
|
#5
|
||||
|
||||
|
Quote:
Yup. Works fine.
__________________
Raid1 in XP Pro My open source projects: ------------------------ Blobber - Add images as blobs to SQL Server ------------------------ |
|
#6
|
||||||
|
||||||
|
Quote:
Easy. sql Code:
I know a lot of the features in MySQL can be daunting. But just get your hands dirty, have a play. No better way to learn and its a lot easier than it seems. |
|
#7
|
||||
|
||||
|
There are several PHP based database abstractions that make this as easy as it is going to get.
__________________
"Strange women lying in ponds distributing swords is no basis for a system of government. Supreme executive power derives from a mandate from the masses, not from some farcical aquatic ceremony! Well, but you can't expect to wield supreme executive power just 'cause some watery tart threw a sword at you! I mean, if I went 'round saying I was an emperor just because some moistened bint had lobbed a scimitar at me, they'd put me away!" |
|
#8
|
|||
|
|||
|
Quote:
Yes, but only in IDMS/R on a mainframe ![]() |
|
#9
|
||||
|
||||
|
The ADODB database library for PHP supports transactions in MySQL, oracle, and a number of others. Transactions are as easy as:
PHP Code:
-Dan
__________________
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > PHP Development > PHP-General - Undo MySQL Queries |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|