This is an old revision of the document!
Request for Comments: ext/mysql deprecation
- Version: 1.1.2
- Date: 2012-11-28
- Author: Adam Harvey email@example.com
- Status: Under Discussion
- First Published at: https://wiki.php.net/rfc/mysql_deprecation
- Trivial patch: http://files.adamharvey.name/mysql-deprecation.patch
This RFC proposes to generate E_DEPRECATED errors when connecting to a MySQL database with the ext/mysql API.
In July 2011, Philip started a discussion on the Internals mailing list around the path forward for deprecating ext/mysql, as had been discussed informally for many years. It was agreed at the time that the first step would be to add warnings to the manual, which was done in June.
At the time, it was suggested that we revisit not adding deprecation errors to php-src until 5.5/6.0. Ergo, this RFC.
As a subsequent step, I propose that we generate E_DEPRECATED errors when users connect to MySQL: whether through mysql_connect(), mysql_pconnect() or the implicit connection functionality built into ext/mysql.
The proposed wording of the deprecation message is:
The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead
I'll quote from last year's discussion, rather than writing a long screed myself.
The documentation team is discussing the database security situation, and educating users to move away from the commonly used ext/mysql extension is part of this.
Later, Johannes wrote:
Moving away from ext/mysql is not only about security but also about having access to all features of the MySQL database.
ext/mysql was built for MySQL 3.23 and only got very few additions since then while mostly keeping compatibility with this old version which makes the code a bit harder to maintain. From top of my head missing features not support be ext/mysql include:* Stored Procedures (can't handle multiple result sets) * Prepared Statements * Encryption (SSL) * Compression * Full Charset support * ...
So moving away from ext/mysql is a good thing.
None of those reasons have gone away.
Ulf Wendel has also written a terrific blog post explaining why upgrading from ext/mysql is a good idea.
I don't believe either of these issues are significant enough to justify delaying the deprecation of ext/mysql, but they're both concerns I've heard from users.
There are thousands of tutorials out there that teach users PHP using ext/mysql. Many of these tutorials also teach other outdated practices, such as magic quotes, improper (or no) escaping of user input and use of register globals, but undoubtedly some are also still of value. Removing ext/mysql in future will make these tutorials at best useless, and at worst, impediments to PHP takeup.
Large Existing Codebase
There is also a huge amount of code out there that relies on ext/mysql. At the very least, a compatibility library will need to be developed if ext/mysql is to ever be unbundled.
Possible Future Action
Some future release of PHP will presumably unbundle ext/mysql, at which point it can be moved out to PECL to slowly bitrot. That future release is not part of this RFC, however.
Converting to MySQLi or PDO
An up to date resource is needed here.
Suppressing deprecation warnings
While code is being converted to MySQLi, E_DEPRECATED errors can be suppressed by setting error_reporting in php.ini to exclude E_DEPRECATED:
error_reporting = E_ALL ^ E_DEPRECATED
Note that this will also hide other deprecation warnings, however, which may be for things other than MySQL.
- 1.1.2 (2012-11-28): Replace the Oracle Wiki link with a link to Ulf's new blog post.
- 1.1.1 (2012-11-19): Added the wording of the deprecation message that was already in the patch.
- 1.1 (2012-11-13): Added workarounds; fixed formatting on the quote of Johannes' e-mail.
- 1.0 (2012-11-12): Initial version.