IN THIS CHAPTER
Examining the schema and properties of the database class
Adding Data to MySQL with WordPress
Retrieving data from MySQL with WordPress
Preventing SQL injection
If you've been developing Web sites or applications with PHP for any length of time, you are probably familiar with PHP database functions such as
mysql_fetch_array(), and so on. You might also be familiar with database abstraction classes. Like other abstraction classes, the database class used by WordPress provides an abstraction layer between the developer and the raw MySQL functions in PHP.
A database abstraction layer is a class or library that sits between your code and a series of databases. As every database has its own nuances, and the built-in database functions are messy and inconsistent, a database abstraction layer sorts out that messiness by providing a consistent interface to multiple databases.
The database class used by WordPress — ezSQL — is an extremely lightweight MySQL database abstraction class that, like much of WordPress' core, originated elsewhere. The original author, Justin Vincent, still maintains this class at
www.woyano.com/jv/ezsql. It can be found in WordPress in
Before diving too far in, you should take note that ezSQL is not a database abstraction layer; it is a MySQL abstraction layer. It is possible, however, to take the
wp-db.php file and manipulate it to talk to other database systems ...