Re: New PDO-based DBAL/ORM for PEAR2
| From: | Michael J. I. Jackson | Date: | Wed, 21 Nov 2007 21:04:54 +0000 |
| Subject: | Re: New PDO-based DBAL/ORM for PEAR2 | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-48568@lists.php.net to get a copy of this message | ||
Hey David,
Sorry it took me a long time to respond to this one. I wanted to think about it first.
On Nov 20, 2007, at 9:14 PM, David Coallier wrote:
Bah pseudo code is annoying let's just try to make a fake directory
structure and a factory method here.
Imagine class SuperORM
File: SuperORM.php
class SuperORM
{
/**
* $name and $dsn would really only be $dsn and you handle
* the name according to the dsn passed but that'll be simpler in
* that example.
*/
I don't get this part here...how do you tell which kind of connection they want with just a DSN?
$db = SuperORM::factory('mysql:host=localhost');
or
$db = SuperORM::factory('mysql://user@localhost');
I mean, it's doable. But it's a multi-signature mess... MDB2::parseDSN() is already long enough. I was kind of trying to avoid something like that.
Which means that it can be any kind of driver really...so in order to abstract anything you need to check what kind of driver it is later at some point...why not just take care of this up front? And why create another MySQL-specific driver when this one works on MySQL just fine?public static function factory($name, $dsn) { $file = ucfirst($name) . '.php'; $class = 'SuperORM_Driver_' . ucfirst($name);// This of course would go in allfiles or autoload.... /** * This is a long way to say the file./SuperORM/Driver/$name.php really..*/ require dirname(__FILE__) . DIRECTORY_SEPARATOR . __CLASS__ . DIRECTORY_SEPARATOR .'Driver' . DIRECTORY_SEPARATOR $file;$new = $class::factory($dsn);return $new; }} // Here you have your simple class with a simple factory. File: SuperORM/Driver/Pdo.php class SuperORM_Driver_Pdo extends WhicheverWeNeedAbstract {public static function factory($dsn) { // Do all the PDO specific tasks and instantiation, etc etc. return new $pdoObject; // Whatever.. }} // Here you have your PDO driver
File: SuperORM/Driver/Mysql.php class SuperORM_Driver_Mysql extends WhicheverWeNeedAbstract {I think I get what you mean...I'm just not convinced yet. If I need to query the database, it shouldn't matter whether I use mysql_query() or PDO::query(), right? As far as I can see that's really all we're talking about here... Michael P.S. How many email addresses do you have? ; )public static function factory($dsn) { // Handle all the native infos here (Still using your ownconstants for attributes and random values)return new $mysqlObject; }} // Here you have your mysql specific driver What I am trying to show you is something I am sure you already know but just that you should not be using all the PDO::ATTR_* within the main class/factory because this will limit you to PDO only. If I look at your current code, the PDORM factory seems to be using a lot of PDO::ATTR_* which is setting barriers, keeping you within the distance of PDO only. Hmm, do you get what I mean ?