RE: [PEAR-DEV] MDB 2.x
| From: | Lukas Smith | Date: | Tue, 26 Aug 2003 09:27:53 +0000 |
| Subject: | RE: [PEAR-DEV] MDB 2.x | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-20522@lists.php.net to get a copy of this message | ||
> From: Alan Knowles [mailto:alan@akbkhome.com]
> Sent: Tuesday, August 26, 2003 11:22 AM
> Just been playing with it.. - a few more feature requests... :)
>
> A)
> would it be worth considering adding as many native types as possible
to
> the drivers?
>
> possibly in a format like this...
>
> within type/common..
> getDeclaration($db,$type,$name,$fields) {
>
> if (method_exists("get{$type}Declaration",$this)) {
> return $this->{"get{$type}Declaration"}($db,
> $name,$fields);
> }
> return MDB::RaiseError();
> }
>
> I really needed to use varchar.. today..
well basically the new structure allows you to more easily add code like
that. Also the new manager will be able to take full advantage of this
flexibility.
> B) for the modules, a more generic loader mechanism would be nice..
>
> eg.
> $manager = &MDB_Manager::factory('mysql');
>
> $types = &MDB_DataTypes::factory('mysql');
>
> function &factory($driver) {
> $mdb = MDB::factory($driver);
> return $mdb->loadModule('manager');
> }
well this is already possible, just not through the factory.
The new MDB_Common::loadModule allows you to define an arbitrary class
which is loaded into a given property.
So something like this should give you the requested result:
$mdb->Connect($dsn);
$mdb->loadModule('foo', 'datatype'):
$mdb->loadModule('bar', 'manager'):
I may add a bit more flexibility to MDB::setOptions() down the road.
> C) consider loading the connection into the class when you create it..
> eg..
> in loadModule
> $this->{$module} = new $class;
> $this->{$module}->db = &$this;
> reutrn $this->{$module};
> }
> that way you dont need to keep passing $db to all the methods....?
well the reason why I did it this way is to prevent resursive references
$mdb->manager->db would point to $mdb ...
kinda ugly.
For the extended module I also did it to enable static calls
MDB_Extended::queryAll($db, $sql, ...)
Regards,
Lukas