I am definitely in favour of this. The destination has to be an OOP interface with placeholders. I think placeholders speaks for itself. OOP needs more justification, but here are the benefits I see:
1) Allows mocking of functions for unit testing. Without this, unit testing Moodle is hard to impossible in almost all legacy areas (e.g. quiz). Note that the one area of Moodle with good unit tests is the gradebook that was just rewritten from scratch.
2) It enables you to have connections to more than one database (possibly with different prefixes). That helps enrolment plugins. Also it enables other things. I'll add an example later.
As to how we get to this destination. Well I don't have any good ideas myself, but it will clearly cause a lot of short-term pain to a lot of people, so it is good that other people are thinking about this and seem to be coming up with good thoughts.
OK, an example of a interesting use of OOP datalib. This is something we have considered doing here using a nasty trick like messing with the $db global.
You know the way the moodle.org grinds to a halt for a few minutes each day when it sends out the forum cron emails, because that hammers the DB. Well, to avoid that, you could consider setting up a second database that is a read-only mirror of the first, and run all the huge read-only reporting SQL against that, in cases where you don't really mind if the data show is missing the last few minutes live data. So logs and stats reports, quiz and gradebook exports (not on screen where current data is more important and it is paged) some parts of cron etc.
To enable this, inside Moodle you would have two objects, $mdb and $reportingdb. Normally $reportingdb would connect to the same database as $mdb, but to ensure developers don't make mistakes, it would have to use a datalib subclass that gives an error if you call any of write datalib functions. Then gradually, you could move a few areas of the code to the new $reportingdb class for some queries, and some admins could set up the necessary replication, change the $reportingdb connection, and start moving the reporting load off of the main transactional database. That might even let you tune the two servers better. Apparently the OU uses this sort of setup for a lot of our other system, which is why we thought about doing the same for Moodle.
Some discussion on MHQ today about this - some agreement (from Eloy and me) to move to an OOP DB handle, AdoDB-style (perhaps as an AdoDB subclass, or a just a wrapper).
I mentioned the discussion on this with Tim Hunt at Moot UK - outline of what I remember
The main conflict is around addslashes() and magic_quotes. Here's what I recall (IIRC!)
One of the big benefits of the above plan is that - even if we remove it for the released 2.0, it means that the work can be more gradual, while having a working HEAD. Avoids huge all-or-nothing patches and hard-to-maintain dev branches.
- switch core moodle + modules to a the new OO dmllib, with calls like $mdb->get_records()
- with a bit of work, it can allow us to keep legacy function calls like get_records() around without conflict for a while
- it also allows us to rework things like what parameters they take - so we can re-design the API and drop things that have been bad ideas.
The main conflict is around addslashes() and magic_quotes. Here's what I recall (IIRC!)- during the transition (while working), keep the automatic magic_quotes on
- converted files can define NOPLEASENOMAGICQUOTES just before including config.php so lib/setup.php skips them
- the legacy dmllib, when running insert_record/update_record()/select* runs striplashes and passes the call on to the new OO dmllib (which will use placeholders) - no security risk there - at the most we might strip an extra backslash accidentally
- once we are done, disable the automatic magic quotes and put warnings in the old dmllib calls - provide a switch in admin to enable auto magicquotes for legacy modules
One of the big benefits of the above plan is that - even if we remove it for the released 2.0, it means that the work can be more gradual, while having a working HEAD. Avoids huge all-or-nothing patches and hard-to-maintain dev branches.