How to Restore Legacy mysql to php7 - when you really hate mysqli

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. Sorry guys. However, there is another work around to restore your old mysql without breaking the bank.  My other alternative is to use a mysqli wrapper. See my other blog post:.
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:
https://github.com/php/php-src/tree/PRE_PHP7_EREG_MYSQL_REMOVALS/ext/mysql
Either:
1
2
cd ext/
or
or
http://pecl.php.net/package/mysql
(same code, same timestamp, now static and likely will never be updated again)
Then compile the code on your server:
1
2
3
4
phpize
./configure
make
make install
The “make install” should announce where it is copying mysql.so – 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:
1
extension = /usr/local/lib/php/extensions/no-debug-non-zts-20151012/mysql.so
(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-mysqlon 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.
1
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.

Comments

Popular posts from this blog

Microsoft Visio 2010 Premium Product Keys

Mercedes Benz Diesel CDI EGR Emulator Circuit Diagrams

Fix: The Diagnostic Service Host service failed to start due to the following error. [ solved, no kidding ]