Re: PEAR and DB abstraction layer (was: PHPLIB)
| From: | Manuel Lemos | Date: | Tue, 27 Jun 2000 03:43:01 +0000 |
| Subject: | Re: PEAR and DB abstraction layer (was: PHPLIB) | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-651@lists.php.net to get a copy of this message | ||
Precedence: bulk
Hello Jennifer,
On 26-Jun-00 21:46:24, you wrote:
>>You're a brave man. Some days ago I had to drop using PEAR's DB
>>abstraction layer for a project because it didn't seem to work at the
>>time, and I couldn't find authoritative docs.
>Could someone direct me where to find out more about PEAR?
It comes with PHP source distribution and gets installed in
/usr/local/lib/php by default under Unix systems.
>Also, could someone explain to me what an abstraction layer is?
It is a way to access to different databases database (hopefully) using the
same procedures.
While you are at it, you may want to look into Metabase which is also a PHP
database abstraction package that goes a little beyond other existing
abstraction packages.
Metabase is now very mature in the provide true abstraction not only at
database access functions level but also at data handling.
For instance, each databases handles dates in their own way. Many database
abstraction packages don't help on this and you still have to handle the
differences in database formatting on you're application. That is not a good
thing because you're application does not become truly portable.
Metabase solves this by abstracting data types: text, integer, float,
decimal, date, time and timestamp. Regardless of the database format that
is used by the database, Metabase does any necessary format conversion to
assure that your application only has to handle dates in the ISO 9601
format (YYYY-MM-DD).
Another interesting aspect is that Metabase provides data type emulation if
necessary. For instance, let's say you want to your database application
to handle money values.
Using floating point fields to store money values is a beginners mistake.
Floating fields are not accurate. Money values have to be handled with
accuracy. Ideally you would use decimal (fixed point) fields but popular
databases like MySQL don't support them. You can't use text fields because
you won't be able to use arithmetic or summary functions in SQL with text
fields.
Metabase MySQL driver emulates decimal fields using integer fields.
Internally it performs any necessary decimal place shifting when sending or
retrieving decimal fields from the database.
Metabase has many other nice database access abstraction features that are
highly desirable for Web applications like restricting the range of result
rows that is retrieved from the database. In MySQL you would use the LIMIT
clause but not every database has that (AFAIK only recent versions of
PostgreSQL support that). Metabase supports that with a single function
that is implemented by each database driver in a way that is appropriate to
each one.
Metabase is not only about database access but it provides also nice
support to manage schemas in a database independent way. Metabase comes
with a parser that extracts the structure of your database schema objects
(tables, fields, indexes and sequences) from a custom XML file that is easy
to edit by hand.
Then Metabase manager is able to take the parsed database structure
information and execute the necessary statments to create and install you
database schema objects. Once again you don't have to put up with database
differences nor have to write SQL statements by hand.
If later you want to change your database schema, all you have to do is to
edit the schema description file and ask Metabase manager to update the
schema from it. The manager will compare the new schema version with the
previously installed schema and extracts the changes. Then it applies the
changes without affecting data that was added to the database since it was
installed for the first time or upgraded for the last time.
There is much more to say about Metabase capabilities but this should be
enough to make you curious about it. Here you may find Metabase for free
with through reference manual and a nice tutorial to get you started
quickly.
http://phpclasses.UpperDesign.com/browse.html/package/20
Regards,
Manuel Lemos
Web Programming Components using PHP Classes.
Look at: http://phpclasses.UpperDesign.com/?user=mlemos@acm.org
--
E-mail: mlemos@acm.org
URL: http://www.mlemos.e-na.net/
PGP key: http://www.mlemos.e-na.net/ManuelLemos.pgp
--