DB redesign idea
| From: | Stig S. Bakken | Date: | Fri, 19 Jan 2001 21:21:44 +0000 |
| Subject: | DB redesign idea | ||
| Groups: | php.pear | ||
| Request: | Send a blank email to php-pear+get-1089@lists.php.net to get a copy of this message | ||
I got an idea this morning for making the customization model of DB much
more flexible in a backwards-compatible way. Basically, the objects
returned by DB::connect and DB::factory are of _one_ class, but using
handler objects for conversions between the different layers:
- the bare-bones abstracted API but with no query-manipulation
- a basic "SQL compatibility" layer (today's DB_xxx::modifyQuery)
- higher-level abstraction such as Metabase
So instead of inheriting DB_common and specializing it, you instantiate
DB_connection (or something) and set handler objects for the PHP API,
SQL syntax and a user-defined layer on top of that. Example file
structure:
DB.php
DB/mysql/api.php
DB/mysql/syntax.php
DB/oci8/api.php
DB/oci8/syntax.php
...
When you do "DB::connect('odbc(mssql)://mydsn')", DB will do this:
1. create a DB_connection object
2. instantiate a DB_odbc_api object and set that as the api handler
3. instantiate a DB_mssql_syntax object and set that as the query
handler
For example, when connecting through a real ODBC driver manager (3) is a
necessity if you want to rewrite queries, because you don't know whether
it's MySQL or Oracle behind the Data Source Name before connecting to
it.
The really cool new thing is being able to add more such handlers
though. That way we can be compatible with Metabase (XML schema
definitions and all) without sacrificing the simplicity and performance
of the simple interface.
What do you think?
- Stig