schenk / responsive-flickr-gallery

Responsive galleries from your Flickr photos for your WordPress site.
http://wordpress.org/plugins/responsive-flickr-gallery/
GNU General Public License v3.0
1 stars 4 forks source link

Make compatible with PHP 5.5 / Avoid mysql_*() functions. / bounty anyone? #16

Open larsschenk opened 10 years ago

larsschenk commented 10 years ago

MySQL in WordPress 3.9 – Implications for Plugin Authors by Samuel Wood (Otto) If you're a plugin developer and you have a plugin using any of the php mysql functions directly, then you might start to see breakage in WordPress 3.9.

See, the php mysql extension is very old. As of PHP 5.5, it's also deprecated and will very likely not be receiving further updates.

So starting in WordPress 3.9, if PHP 5.5 is being used, the built in WPDB class will switch to using the mysqli extension instead.

What this means for your plugin is that if you're using any mysql_* functions directly, and somebody tries to use your plugin on a WordPress 3.9 + PHP 5.5 system, then all your database code will no longer work properly. Since the mysql functions are no longer being used in such a case by WordPress, then there is no longer an implicit database connection available to these function calls.

Instead of using a direct database connection, you can switch to using the global $wpdb instance of the WPDB class to access the database. @pento gives a great rundown on what functions to use as drop-in replacements on this make/core post: http://make.wordpress.org/core/2014/04/07/mysql-in-wordpress-3-9/

Now, as this is currently limited to PHP 5.5 and up only, the amount of breakage will likely be very minor. Our stats currently show that PHP 5.5 is being used on less than 1% of installations. Nevertheless, hosts are starting to upgrade PHP versions more and more frequently. This number is thus expected to grow over the next year or two. So before your users start having broken sites, please, take the time to switch your plugins over to the WPDB based methods. This will ensure future compatibility and minimal breakage.

WordPress will always maintain backward compatibility in its own functions, so using them ensures that you'll be good for the forseeable future, no matter what database methods are being used internally.