11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 31 • INTRODUCING PDOwww.it-ebooks.infoIt’s likely you’ve heard of some of the more widespread implementations:• MDB2: MDB2 is a database abstraction layer written in <strong>PHP</strong> and available as aPEAR package (see Chapter 11 for more information about PEAR). It presentlysupports FrontBase, InterBase, <strong>MySQL</strong>, Oracle, PostgreSQL, QuerySim, andSQLite.• JDBC: As its name implies, the Java Database Connectivity (JDBC) standard allowsJava programs to interact with any database for which a JDBC driver is available.Among others, this includes Microsoft SQL Server, <strong>MySQL</strong>, Oracle, andPostgreSQL.• ODBC: The Open Database Connectivity (ODBC) interface is one of the mostwidespread abstraction implementations in use today, supported by a wide rangeof applications and languages, <strong>PHP</strong> included. ODBC drivers are offered by allmainstream databases, including those referenced in the above JDBCintroduction.• Perl DBI: The Perl Database Interface module is Perl’s standardized means forcommunicating with a database, and it was the inspiration behind <strong>PHP</strong>’s DBpackage.Because <strong>PHP</strong> offers MDB2 and supports ODBC, it seems that your database abstraction needs areresolved when developing <strong>PHP</strong>-driven applications, right? While these (and many other) solutions arereadily available, an even better solution has been in development for some time. Officially released with<strong>PHP</strong> 5.1, this solution is known as the <strong>PHP</strong> Data Objects (PDO) abstraction layer.Another Database Abstraction Layer?As PDO came to fruition, it was met with no shortage of rumblings from developers either involved inthe development of alternative database abstraction layers, or perhaps too focused on PDO’s databaseabstraction features rather than the entire array of capabilities it offers. Indeed, PDO serves as an idealreplacement for the MDB2 PEAR package and similar solutions. However, PDO is actually much morethan just a database abstraction layer, offering:• Coding consistency: Because <strong>PHP</strong>’s various database extensions are writtenby a host of different contributors, the coding approaches are quiteinconsistent despite the common set of features. PDO removes thisinconsistency by offering a single interface that is uniform no matter thedatabase. Furthermore, the extension is broken into two distinct components:the PDO core contains most of the <strong>PHP</strong>-specific code, leaving the variousdrivers to focus solely on the data. Also, the PDO developers took advantageof considerable knowledge and experience while previously building andmaintaining the native database extensions, capitalizing upon what wassuccessful and being careful to avoid what was not. Although a fewinconsistencies remain, by and large the database features are nicelyabstracted.• Flexibility: Because PDO loads the desired database driver at run time, there’sno need to reconfigure and recompile <strong>PHP</strong> every time a different database isused. For instance, if your database needs suddenly switch from Oracle to608

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!