PHP 7 ext/mysql Shim

This post is over 1 year old and is probably out of date.

To help ease the transition from 5.6 to 7.0 I have created a simple package that acts as a shim between the newly removed ext/mysql and ext/mysqli.

I was a little hesistent to even publish this as I don’t want to encourage the continued use of potentially insecure code, however, I want people to upgrade to 7.0 and don’t want this to be the blocker.

It does require 5.6 (though it would be possible to lower that) — however I suspect that most people who are upgrading to 7.0 are either coming from 5.6 or have the native ext/mysql. The primary reason for support 5.6 is to be able to compare the test suite results against native ext/mysql.

It’s not yet production ready, but tests are coming along pretty well (PRs welcome!):

Build Status Scrutinizer Code Quality Code Coverage

Current known (and unlikely to be fixed) issues are:

  • You must prefix all calls to mysql_* with a \ (e.g. \mysql_connect()); Not sure why I thought this, but non-internal functions do fall back to the global namespace.
  • Calls to is_resource() and get_resource_type() on MySQL connections and results will fail as these are now their mysqli equivalents.
    -Some errors are now from ext/mysqli, and others are E_USER_WARNING instead of E_WARNING. Where possible, the original error messages are replicated.
  • Column lengths reported by mysql_field_len() assume latin1 charset, and will return incorrect lengths for other charsets.

You can check it out now on Github.

Image Courtesy of Egan Snow, used under a CC-BY-SA 2.0 license.