PHP Developers Network
http://forums.devnetwork.net/

DB transactions discussion
http://forums.devnetwork.net/viewtopic.php?f=19&t=138621
Page 1 of 1

Author:  BDKR [ Wed Oct 23, 2013 3:31 pm ]
Post subject:  DB transactions discussion

I've been shocked recently to encounter a bit of resistance to using database level transactions. You know... Begin, Rollback, Commit.

Instead, I hear the bloke saying things like, "Since you already have the ID's, you could just delete the record". Now while that may sound simple enough, how is that easier then just saying "Rollback" to
the db?

I've used them where appropriate for some time now ('02 was the first) and can't begin to understand why someone would take such a stance. Is there something that I don't understand?

Author:  Christopher [ Wed Oct 23, 2013 5:17 pm ]
Post subject:  Re: DB transactions discussion

I get the impression that some programmers, especially those that are self-taught or learned on very simple websites, have very little understanding of what databases are capable of. This is very different from old school style of offloading complex operations to the database with features like transactions, triggers, stored procedures, etc. This is both good and bad. There is a modern trend to simplicity in database use. NoSQL database usage is the most obvious examples of this.

Also, if you consider you Model to be an interface to some abstract datasource out there somewhere -- maybe a database / maybe a webservice -- then it might make sense to not assume transaction capability and do your own rollback on an error.

That being said, and unlike triggers or stored procedures, transactions are a very standard, portable part of SQL. They really should be used for cases where multiple SQL statements are a related group and must be undone if there is a failure at any point. So I think there may be a little DIY ignorance when transactions are not used.

PS - welcome back BDKR!

Author:  BDKR [ Wed Oct 30, 2013 3:22 pm ]
Post subject:  Re: DB transactions discussion


Author:  josh [ Sat Nov 02, 2013 12:30 am ]
Post subject:  Re: DB transactions discussion

Well why are you inserting rows just to delete them or roll them back, might as well use a temp table if I understand right. Or maybe even a sqllite in memory database that you delete after you're done. Or just don't use a database at all if you don't need persistence.

Author:  BDKR [ Fri Nov 08, 2013 11:46 am ]
Post subject:  Re: DB transactions discussion


Author:  matthijs [ Tue Nov 12, 2013 12:30 pm ]
Post subject:  Re: DB transactions discussion

Agreed. I think that whenever you run multiple queries and a problem half way could leave the db in a corrupted state, you should use transactions.

Maybe the problem is also that many examples, articles and tutorials are pretty basic, with very simple examples. Insert this, update that and done. Very little thought on possible problems, security, etc

Author:  josh [ Fri Nov 29, 2013 9:53 pm ]
Post subject:  Re: DB transactions discussion


Author:  VladSun [ Mon Dec 23, 2013 12:04 pm ]
Post subject:  Re: DB transactions discussion


Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/