Re: Database abstraction
| From: | Martin Marques | Date: | Tue, 13 Jan 2004 22:40:05 +0000 |
| Subject: | Re: Database abstraction | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-32379@lists.php.net to get a copy of this message | ||
Mensaje citado por Malte Starostik <malte.starostik@t-online.de>:
> Hi,
>
> I've read several posts touching this subject, but I didn't find one that
> asks a simple question I've been wondering about since I first used PHP and
> that is also one of the two really really bad things about PHP (the other
> being lack of OO):
PHP5 deals with this.
http://ar.php.net/manual/en/faq.general.php#faq.general.relation-versions
> Why isn't there a DB abstraction layer right in PHP, so people writing some
> web app for redistribution don't have to care about the different DBs
> themselves?
Use PEAR::DB or PEAR::MDB.
> Why is there no modularization in this area, such that it'd be the _normal_
> way not to write things like $dbh = ibase_pconnect( ... ), but $dbh =
> sql_connect( "Firebird", ... )
With PEAR::DB all you have to do is build a string like this:
$dsn = "pgsql://username:password@hostspec/database_name";
And I will be running PostgreSQL so that later all I have to do is:
$db = DB::Connect($dsn);
$db->query("SELECT * FROM tabname");
> and that would internally check if a Firebird/InterBase driver is available
> and if so, use it.
> Surely there are some differences in SQL conformance and syntax extensions,
> but even that could be handled by such a layer to some extent.
See this:
http://pear.php.net/manual/en/package.database.db.intro-dsn.php
--
select 'mmarques' || '@' || 'unl.edu.ar' AS email;
---------------------------------------------------------
Martín Marqués | Programador, DBA
Centro de Telemática | Administrador
Universidad Nacional
del Litoral
---------------------------------------------------------