Connecting to a MySQL database using PDO

PDO, is an extension that allows us to have a consistent way of interfacing with databases, making our communication much easier from within our project. Since PDO and all it returns is in OOP form, our object or our PDO PHP data object is an instant of the PDO class. That object it will have its own variables called properties, and its own built in functions or methods.

Managing Errors

A great benefit of PDO is that it has an exception class to handle any problems that may occur in our database queries. If an exception is thrown within the try{ } block, the script stops executing and flows directly to the first catch(){ } block. Managing errors in any application is very important, especially when it comes to database errors.

Useful resource on PDO:

Code used in this tutorial

If you are using Windows/XAMP – Use password=’ ‘;

MAC and MAMP – Use password=’root ‘;

You can download –  PDO connection files (56 downloads)

Leave a Reply

Your email address will not be published.

XL Websites

XL Websites