[UPHPU] Data abstraction layer clarification

Alvaro Carrasco alvaro at epliant.com
Wed Apr 16 15:51:06 MDT 2008


Nathan Lane wrote:
> I was googling "PHP best practices" and came across this
> website<http://www.odi.ch/prog/design/php/guide.php>,
> and it states,
>
> "In PHP there are no database-independent functions for database access
> apart from ODBC (which nobody uses on Linux). You should not use the
> PHPdatabase functions directly because this makes it expensive when
> the
> database product changes. Your customer may move from MySQL to Oracle one
> day or you will need an XML database maybe. You never know. Moreover an
> abstraction layer can ease development as the PHP database functions are not
> very userfriendly."
>
> Which seems to say to me, "don't ever use PHP to access the database
> directly," yet I'm sure that's not what's it's saying. Can anybody clarify?
> My intent was to create a layer of classes and functions that allow me to
> access the database transparently for what I need - probably some sort of
> Active Record methodology would be implemented. Is that what is being said
> here, or is it saying what I perceived it to say?
>
>   
They're recommending that you use some sort database abstraction library 
such as ADODB or Pear_DB to smooth out the different sql syntax required 
by different database vendors. If you're not worried about switching 
databases and don't mind the native functions you're OK to use them. The 
abstraction libraries generally provide a much nicer API, so I would 
recommend using them.
PHP 5 now has PDO, but depending on your needs it may or may not give 
you enough abstraction.

Alvaro


More information about the UPHPU mailing list