Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Throughout this course, I've deliberately avoided comparing PDO and MySQL improved, but now we've come to the end of our journey. Maybe this is an appropriate time to consider how they measure up against each other. PDO's main strength, is that the code is database neutral. You need to learn only one API to work with more than a dozen database systems. In theory, just change the DSN, and the same code works with a different database. All the scripts in chapters two, three and four, work seamlessly with SQL Lite and My SQL.
In practice, differences in SQL dialects make conversion more difficult. Also, some PDO drivers are still experimental. So, you need to check with the PHP documentation, to see how mature the driver for your chosen database system is. MySQL improves great strength, is that it's designed specifically to work with MySQL. A simple example's, the data_seek method and num_rows property, make working with MYSQL easier than using PDO.
It's also what MySQL recommends you should use. But being a dedicated API is a weakness. You can't use it with anything other than MySQL or MariaDB. Another point to take into consideration, is that the PDO driver for MySQL, is stable and actively maintained. So using PDO with MySQL, is a viable option. So if you're working with MySQL, which should you choose? If you search the internet for benchmark tests, you'll find conflicting opinions on whether MySQL runs faster with MySQLi, or PDO.
Both MySQLi and PDO access the same underlying driver that interacts directly with the database. So any differences in performance, are likely to be insignificant. WordPress and Joomla, use MySQLi, while Drupal has opted for PDO. And WordPress is also considering adding support for PDO. So there's no clear winner when it comes to working with MySQL or MariaDB. But let's say you opt for MySQLi, and later need to work on a project that requires PDO.
How difficult would it be to make the transition? If you followed both parts of this course, you'll know there are many similarities, but also some potentially confusing differences. Both support question marks as anonymous place holders in prepared statements. PDO also supports named place holders. Personally, I think this makes PDO easier to use. They have similar support for transactions. In PDO, you roll back the individual statements.
Whereas in MySQLi, it's the database connection object that does the roll back, perhaps the most confusing aspect is the different spelling of methods, PDO uses camel case whereas MySQLi uses underscores and method names but these are relatively minor issues. Making the switch from MySQLi to PDO should be fairly painless. So, with those thoughts, that concludes this course on accessing databases with object oriented PHP.
I hope you found it useful. Thanks for watching, and be sure to check out my other courses here on lynda.com.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 96599 Viewers
56 Video lessons · 110325 Viewers
71 Video lessons · 79148 Viewers
131 Video lessons · 37945 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.