Hi folks. Given the last response by Justin to my comment about some people's dislike for DB abstraction layers I'm electing to throw this out into the general discussion as a new topic.
I have mixed feelings about abstraction layers. At times I love them (mostly) and at times I hate them. I posted a problem to a postgresql forum recently where I was having a query return different results from the command line and from within PHP, and it turned out to be a bug in ADOdb's debugging code which was the problem, incorrectly reporting the query which had just run ('%,123' is not the same as '%, 123' but it will drive you insane!!!!! ;o). I hated it for a brief time then ;o)
The link below points to a page which contains a message from someone in response to my post looking for help solving the above problem, someone whom I consider to be quite, quite knowledgeable about databases and whose opinion I very much respect, so I think it deserves a read. It makes some interesting points:
http://web.unbc.ca/~gossep/dbx.html
Anybody care to throw their hat into the ring for a debate on the pros and cons of using DB abstraction layers such as ADOdb (which I really like) against Pear::DB and PHP's DBX functions, for example??
Cheers,
Pablo
I'll start with a response to the URL you posted.
The author seems to have not looked at PEAR DB very closely. He rants about the extra recordset, looping, and such but there are convenience functions in PEAR DB which handle these things and will even free your result set automatically (if appropriate) whereas the builtin funcitons requirte you to do it for yourself. For instance:
1) Get a single record:
$rec = $db->getRow('SELECT * FROM table WHERE field="value"');
I have never seen any *_fetch_result() functions and searching the PHP manual gives me none, so I have no idea where the author is finding them. AFAIK, this takes 3 lines of code to properly free the result pointer using bare PHP functions
2) Loop through a record set: $sth = $db->query('SELECT * FROM table'); while($rec = $sth->fetchRow()) { //you may also need && !PEAR::isError($rec) in this while // if you have error handling set to PEAR_ERROR_RETURN //do something } $sth->free(); //The following is optional unset($sth); This is pretty damn close to just using builtin functions.
3) Get a single value from a single field in a single record:
$value = $db->getOne('SELECT field FROM table WHERE col="val"');
AFAIK, no builtin functions exist to do this. This would require at least 4 lines to properly get the value and free the result.
It looks like this rant is really focused on ADOdb even though it says it's about all abstraction layers.
<disclaimer>
I have never used ADOdb.
</disclaimer>
<opinion>
From what this person says and a cursory look at the ADOdb manual, I can see where he's coming from. It looks like it's hard to use, and doesn't offer very much extra functionality.
</opinion>
I also see lots of people talking about speed. In my mind, having extra convenience and error handling is far worth the extra load / run time. Apart from that, there's also this coding rule which I agree with almost always. Developer time is far more valuable that runtime. If you spend lots of time working to make your code fast, you spend lots of money that way when you could just be buying faster hardware. In addition, faster code tends to be less readable and harder to maintain. For more, see this URL:
http://www.faqs.org/docs/artu/ch01s06.html#id2878666
I also highly recommend reading that (free) book as it is very well written.
I could say more, but I think I've said enough for now. :-)
-- paperCrane <Justin Patrin>
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php