Re: DBM Compatibility layer
| From: | Alan Knowles | Date: | Mon, 29 Apr 2002 05:01:27 +0000 |
| Subject: | Re: DBM Compatibility layer | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-5868@lists.php.net to get a copy of this message | ||
Brent Cook wrote:
On Mon, 29 Apr 2002, Alan Knowles wrote:As I posted it, i realized my power will be down for about 8 hours today :( - big men with electric cables doing stuff outside ...this is what looks like a different approach - it gets away from the build/execute and produces a more abstract methodoly. http://www.akbkhome.com/Projects/db_oo+-+an+object+based+Sql+builder+and+wrapper+for+peardb/db_oo.class.htmlI had some trouble resolving www.akbkhome.com. Will try again later, and hopefully if I see the code, the examples will make a little more sense to me ;)
originally, you had to define in the Group object which items where in the table Group, I moved away from this to a more 'automated' version.. - it builds a config table for the database defining what columns are integers and what are strings, and which are index columns..On a base level some examples of usage /------------------------------ mulitiple fetch. SELECT *,DATE('YYYY-mm-dd',creation_date) as created FROM Group WHERE firstname='abc' and age > 12 limit 12; $group = new Group; $group->firstname = "abc";This sets a member variable called "firstname" in the group object to "abc", right? How does the Group object know that it has this variable set now? Perhaps when I see the code, all will be clear..
executes the select - the order was wrong - you do the $group->find(), just before the $group->fetch(), find returns the number of rows found (and also sets $group->N to that value). 'a bit more than your standard execute' the class includes (when the sites back up), a standard $group->query($string); to do what find does, run the query and return the number of rows found..., so if you want to build the query manually there is that option.. - its just there is a balance here between hard coding sql and auto building it.. - sometimes the builder is more work than the hand code..$group->find()What does this do?
$group->limit(12); $group->condition_append('age > 12'); $group->select_add("DATE('YYYY-mm-dd',creation_date) as created"); while ($group->fetch()) { echo $group->id; }This still seems to fit the build/execute scheme, which I don't see anything wrong with, BTW. It seems to instead call execute fetch.
Group is an extension of the db_oo (which provides all the functionality).... - technically each instance of the group represents a row in the database, this is a snippet from one of the classes I'm working on at present. the data/table definition is another file (although it can go in here).., it is an auto generated php code (rather than xml) as that is easier/quicker to parse at runtime.. This gives a real life example of updating the domains in a registry class DbDomains extends db_oo {There are quite a few more feature that need more documentation working on, but it the design of it is to help enforce putting all data manipulation / stored selects etc into the extended class, rather than the scripts - so that you would probably end up makingI like that idea.Group::list_pear_developers(); // which which would store the builder for that select in the class - hence helping enforce code reuse, rather than splattering this around the application....If Group is extended, is it still called Group, e.g. class Group extends Group { maybe I misunderstood.
var $__table = "domains";
function &static_get_by_live_domain($name) {
$domain = new DbDomains;
$domain->domain = $name;
$domain->condition_append('status > 9');
$domain->find(1);
if ($domain->N)
return $domain;
}function renew($years) {
// add a few years to the expiry!
list($y,$m,$d) = explode('-',$this->expiry);
$this->expiry = date("Y-m-d",mktime(1,1,1,$m,$d,$y+$years));
$this->update();
}
}
/* this bit is inside the page action class
foreach ($domains as $domainname => $years)
if (
$domain = DBdomains::static_get_by_live_domain($domainname))
$domain->renew($years);
I also started looking at DBM compatiblity - but other than simple insert/updates - the complex selects where a bit much for it...I have finally written a proof-of-concept table object with select, sort and project operators that is implemented on a DBM database. It is located here: http://ozma.union.utexas.edu/~busterb/DBMTable.tar.gz I hope you appreciate the simplicity of the select() function. The idea came to me one day in the shower, after bumping my head ;) will have a look tonight when the house is back online :)
- Brentregards alan