making bbPress (and WordPress) work better!

How to put MySQL functions back into PHP 7

PHP 7 will go “release candidate” on August 20th 2015 which is very exciting because it will instantly be twice as fast as PHP 5.6 (and all previous versions). PHP7 gives HHVM a run for the money and takes 5 minutes to compile instead of hours for HHVM.

But there is a catch – if you have any legacy code that uses the mysql_* functions, they will stop working entirely in PHP 7. Not just a warning, not just deprecated, but gone, fatal.

However, it is easy to get them back without using a wrapper or modifying your code…
I wouldn’t plan on using this solution far past 2016 but it will keep your legacy code running in the meanwhile.

Simply compile the mysql function as a php pecl extension and add one line to your php.ini

First get the mysql extension source which was removed in March:


cd ext/
git clone 	 mysql	 --recursive


cd ext/
svn co mysql

(same code, same timestamp, now static and likely will never be updated again)

Then compile the code on your server:

make install

The “make install” should announce where it is copying – copy that path. It will likely be /usr/local/lib/php/extensions/no-debug-non-zts-20151012/ for PHP 7 but it could vary depending on your server setup.

Then edit your php.ini
Somewhere either in the “Extensions” section or “MySQL” section, simply add this line:

extension = /usr/local/lib/php/extensions/no-debug-non-zts-20151012/

(change path if needed)

Restart PHP and mysql_* functions should now be working again. Check your php error log if you have any problems (should check it periodically anyway). You will also see the MySQL section back in your phpinfo page.

Alternately, compile the mysql support into the PHP binary

It is also possible to compile PHP with the mysql extension built right in, so you don’t need to change the php.ini file – follow these instructions:

Basically you put the mysql source under ext/mysql then clear out any existing configure in the php source root and force buildconf to make a new configure. Then compile php including –with-mysql on the ./configure command line.

Note that PHP 7 deprecates several other functions and is more strict about other things like classes, so you may need to tune your log to be less harsh about warnings.

error_reporting = E_ALL & ~E_STRICT & ~E_DEPRECATED & ~E_NOTICE

But don’t ignore the warnings entirely because “deprecated” will one day turn into completely missing and fatal like mysql functions.

19 responses

  1. Pingback: PHP 7.0 Final will ship November 12th 2015 | _ck_ says...

  2. Pingback: Der PHP 7 Migration Guide -

  3. Anonymous

    December 8, 2015 at 5:21 am

  4. Pingback: PHP7'ye güncelleme nasıl yapılır?

  5. Pingback: Wordpress使用PHP7.0更新紀錄 - 某數's blog

  6. thank you, it worked, i have mysql extension on php 7.0.3

    March 4, 2016 at 12:27 pm

  7. Gianluca

    In these wrappers all mysql and ereg functions are rewritten using mysqli and pcre

    March 15, 2016 at 1:50 pm

  8. Pingback: - » Verwendung von MySQL Funktion in PHP 7

  9. You’re my personal Jesus Christ.

    Thanks a lot!

    April 29, 2016 at 10:19 pm

  10. I haven’t understand from the line:

    Then compile the code on your server:

    May 16, 2016 at 7:40 am

  11. Anonymous

    How to put MySQL functions back into PHP 7 for WINDOWS

    May 31, 2016 at 7:15 am

    • These instructions are mostly meant for linux environments but if you knew how to compile on Windows, in theory it should also work. Alternately you could use the prebuilt php libraries for Windows from Jan-E on

      They also include the mysql functions in their builds.

      May 31, 2016 at 7:48 am

      • Anonymous

        Thanks a lot. It works!

        May 31, 2016 at 10:41 am

  12. Really? You want to use mysql_* functions?😀

    June 10, 2016 at 12:36 am

  13. Pingback: Jak rozfungovat staré mysql_* funkce v PHP7 – Martin Janeček

  14. Pingback: Alte MySQL-Extension unter PHP 7 verwenden « Kreativrauschen

  15. Anonymous

    Tested, works. Thanks a lot!!

    July 29, 2016 at 3:46 am

  16. sandhya

    it isn’t working for me..
    make install perfectly worked. it gives output path like: /usr/lib/php/20151012. but i don’t know to what path i should change in extension path in php.ini file.
    the default was, extension=/path/to/extension/

    August 27, 2016 at 4:16 am

  17. sandhya

    can anyone please help?

    August 27, 2016 at 5:26 am

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s