What is the best way to access a database from PHP?

Mar 12, 2012   //   by phpfreelancer.biz   //   Blog, PHP Tutorial  //  No Comments

choose the MDB2 database abstraction layer from PEAR – it provides a nice, abstracted method to deal with the database. I recommend it, since it allows you to write portable code which can be ported to a different database server without many changes required (for a basic script, just changing the connect call is likely to be sufficient). It is a merge of the old DB and Metabase abstraction layers (DB is still supported for bugfixes, but has been superceded by MDB2).

It offers features like prepare + execute emulation for DBs that don’t support it properly, and allows you to use placeholders which is good practice to avoid SQL injection problems.

It will work with: mysql / mysqli, pgsql (PostgreSQL), oci8 (Oracle), sqllite, msql, mssql (Microsoft SQL Server), sybase, informix, fbsql, ibase, odbc.

Leave a comment

Share This Post

RSS Wordpress News