PHP to Deprecate MySQL Extension in Favor of MySQLi and PDO

The PHP project is working toward “softly” deprecating the mysql extension and its associated functions in favor of the newer (and more secure) mysqli and PDO extensions. They won’t be adding E_DEPRECATED errors for the extension in PHP 5.4, but will consider it in subsequent versions. Instead they will be focusing on education, marking it as deprecated in the documentation, adding new documents about the differences, as well as updating examples throughout to use the more modern functions.

The situation is certainly…interesting. There is a lot of code out there using the older database functions—to the point that I’m more surprised to see PDO or MySQLi in use—and nearly as many tutorials teaching questionable practices that enable injection attacks. It’s going to take quite a long time to move people toward the better extension, especially when you consider how long it took for web hosts to roll out PHP 5 when it’s backwards-compatibility issues were relatively minor.

Deprecating ext/mysql [news.php.net]

  • http://www.problogdesign.com/ Michael Martin

    It will definitely take a while to move everyone over, but without steps like this, it would never happen. I’m quite happy to see them pushing things forward. Far too often, things like these drag on for years and years.

    It’s also nice for new users; having both MySQL options is confusing. What’s the difference? Do you learn both? (Most will learn the old one first I guess, because the syntax is simpler. I know I did)

    Whereas if there is only one real option in the documentation, then you’re going to learn good practices right from the start. It’s in your favour. :)

    • http://www.webmaster-source.com Matt

      I learned the older one because my host didn’t have PHP5 back six or so years ago, and therefore no MySQLi. :)

      But yeah, MySQLi is a bit more difficult to learn from the start. I think PDO is a bit simpler, and it works with PostgreSQL and SQLite, so I wonder if newbies should be encouraged to start with that? It’s probably available on more systems, even. It has been bundled with PHP since 5.1.0, and PECL before that, while MySQLi has only been in the distribution since 5.3.0.