PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Nov 19, 2019 4:45 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Wed Oct 23, 2013 3:31 pm 
Offline
DevNet Resident
User avatar

Joined: Sat Jun 08, 2002 1:24 pm
Posts: 1207
Location: Florida
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?


Top
 Profile  
 
PostPosted: Wed Oct 23, 2013 5:17 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US
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!

_________________
(#10850)


Top
 Profile  
 
PostPosted: Wed Oct 30, 2013 3:22 pm 
Offline
DevNet Resident
User avatar

Joined: Sat Jun 08, 2002 1:24 pm
Posts: 1207
Location: Florida


Top
 Profile  
 
PostPosted: Sat Nov 02, 2013 12:30 am 
Offline
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida
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.


Top
 Profile  
 
PostPosted: Fri Nov 08, 2013 11:46 am 
Offline
DevNet Resident
User avatar

Joined: Sat Jun 08, 2002 1:24 pm
Posts: 1207
Location: Florida


Top
 Profile  
 
PostPosted: Tue Nov 12, 2013 12:30 pm 
Offline
DevNet Master

Joined: Thu Oct 06, 2005 3:57 pm
Posts: 3360
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


Top
 Profile  
 
PostPosted: Fri Nov 29, 2013 9:53 pm 
Offline
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida


Top
 Profile  
 
PostPosted: Mon Dec 23, 2013 12:04 pm 
Offline
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4313
Location: Sofia, Bulgaria

_________________
There are 10 types of people in this world, those who understand binary and those who don't


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group