O'Reilly logo

WordPress® Bible by Aaron Brazell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7. Understanding the WordPress Database Class

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_query(), 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.

Note

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 /wp-includes/wp-db.php.

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required