Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
If you’ve used PHP with MySQL before, you may have used the mysql or mysqli libraries to connect to your database, using functions such as mysql_connect(). For many years, this was a standard way of connecting to MySQL databases, and there were equivalents for other database platforms.
These libraries were used directly and formed the basis of libraries and frameworks for countless PHP applications. The disadvantage was that each extension differed slightly from the others, so making code that could easily move between database platforms was tricky. Although those database-specific libraries are still active and well-maintained, this chapter will focus on using the more modern PDO extension. The PDO extension was created to give us a unified set of functionality when talking to database platforms of all kinds. It’s an object oriented extension that was introduced with PHP 5, taking advantage of many features introduced into the language at that time.