HomePHP Working with Prepared Queries with PDO Objects in PHP 5
Working with Prepared Queries with PDO Objects in PHP 5
If you're a PHP developer who builds web applications that interact with different database systems, such as MySQL, Oracle, MS SQL, and so forth, then this group of articles might be what you're looking for. Welcome to the final part of the series that began with "Using PDO objects in PHP 5." This series shows you how to implement the most important methods that come packaged with the PDO database abstraction layer (short for PHP Data Objects).
In the preceding article of the series, I proceeded to cover in detail a few simple methods bundled with the PDO library for performing some common tasks associated with diverse database systems. These tasks included fetching and counting the number rows present in a given result set, retrieving specific columns, and finally determining how many records were affected after executing an INSERT, UPDATE and DELETE command.
Of course, it's important to stress here that the aforementioned operations, and the ones discussed in the first article of the series, can be easily performed using a great variety of database servers, including the most popular ones, such as MySQL, MS SQL, Oracle. This clearly reveals the real power that stands behind this robust PHP-based database abstraction layer.
Okay, at this point you may be thinking that the functionality brought by PDO objects is limited to connecting to multiple database systems, performing a few basic database-related tasks, and that's it. Actually, the extension has been provided with many more useful features, including its capability for working with prepared queries.
As you'll probably recall, I already introduced the concept of prepared queries through the implementation of the "prepare()" and "execute()" methods of the PDO extension, right at the beginning of this series. As I said then, however, it was only an introduction to the topic.
Indeed, this subject is far much complex, and deserves a more detailed analysis. Therefore, in this last tutorial in the series I'm going to show you how to run prepared queries, but in this case we're going to include named parameters into them. Additionally, I'm going to take a quick look at some additional methods bundled with this extension. These new methods can be really useful for working with transactions, in case you want to use this feature with the database system of your choice.
Hopefully, by the end of this article, you should have a more solid background in how to include these neat characteristics in your own PHP applications with the assistance of the PDO extension.
With the preliminaries out of our way, let's explore the real power of using prepared queries and transactions with PDO objects. It's going to be an instructive experience!