Book Image

Learning PHP Data Objects

By : Dennis Popel
Book Image

Learning PHP Data Objects

By: Dennis Popel

Overview of this book

PDO is lighter, faster, and more powerful than existing PHP data abstraction interfaces. PDO is a common interface to different databases that must be used with a database-specific PDO driver to access a particular database server: the PDO extension does not provide a database abstraction by itself; it doesn't rewrite SQL, emulate missing database features, or perform any database functions using by itself. It performs the same role as other classic database abstraction layers such as ODBC and JDBC: it's a query abstraction layer that abstracts the mechanism for accessing a database and manipulating the returned records; each database driver that implements the PDO interface can also expose database-specific features as regular extension functions. ¬ PDO ships with PHP 5.1, and is available as an extension for PHP 5.0; it requires the new object-oriented features of PHP 5, and cannot run with earlier versions of PHP.This book will teach you how to use the PDO, including its advanced features. Readers need to be aware of the basics of data abstraction and should be familiar with PHP.
Table of Contents (13 chapters)

Designing Our Code


Good application architecture is another key factor of an application, besides the correct data model. As the application that we are going to develop in this chapter, is relatively small, this task is not very complicated. First, we will create two pages that will list books and authors. To begin with, we should think about how these pages would look. To make our simple example small and compact, we will present a header on all pages that will contain links to the books list and the authors list. Later we will add two more pages that will allow us to add an author and a book.

Of course, we should create a common include file that will define the common functions such as the header and footer display and the connection to the database. Our example is really small, so we will not be using any template system or even object-oriented syntax. (Indeed, these topics are beyond the scope of this book.) So, to summarize:

  • All common functions (including code to create the PDO connection...