|Classes of Aziz S. Hussain||>||mysql_* functions using PDO||>||README.md||>||Download|
mysql methods using PDO
This package can be used to access MySQL databases using PDO wrapper functions. It provides a class with functions that can access a MySQL database in a way that is compatible with the original MySQL extension. The package provides global mysql_* functions that can be used when the original MySQL extension is not available with PDO as a backend.
The object duplicates all of the functionality of mysql_* functions except for mysql_info method which I tried to duplicate as best as I can, but due to PDO limitations/my knowledge I can’t do it exact.
In your bootstrap, include:
(OPTIONAL : SEE DRAWBACKS) Update your error reporting to (depending on environment):
(OPTIONAL : SEE DRAWBACKS) If you are using is_resource / get_resource_type for mysql_ methods you will need to replace them with the following functions: is_resource_custom / get_resource_type_custom. You can use your IDE to search replace or the following two lines in your project base:
Who is this for?
This package is for site owners/developers who want to upgrade their PHP version to a version that has the mysql_connect/mysql_* functions removed without having to re-write their entire codebase to replace those functions to PDO or MySQLI.
Why was the mysql extension removed?
mysql_methods are easy to understand, but hard to secure. Since it does not provide Prepared Statements, more developers (beginners in particular) are prone to security risks. Not that mysql_ methods are insecure, but it makes it easier for beginner coders to make insecure queries.
This project can also be found on phpclasses.org: http://www.phpclasses.org/package/8221-PHP-Access-MySQL-databases-using-PDO-wrapper-functions.html
and GitHub: https://github.com/AzizSaleh/mysql
I will try my best to keep them updated.
Drawbacks of this library
Unfortunately due to limitations, there are some things you should know before implementing this library.
Since it is not possible to create resources on the fly in PHP. The following methods will not work as intended:
on the following mysql functions:
To fix, you you will need to replace them with the following functions: is_resource_custom / get_resource_type_custom. You can use your IDE to search replace or the following two lines in your project base:
If you pass a constant to the following methods (ex: string), you will trigger the following error "PHP Strict Standards: Only variables should be passed by reference" in PHP strict error mode (errro_reporting(>= 30720)):
To fix, you will need to change your error reporting hide strict standards (anything <= 30719). Examples:
There are 2 unit tests available in this project:
Associating an existing PDO instance
Simple pass in your PDO object to
If you run into any issues, bugs, features or make things better please send them to me and I will get them in as soon as I can.
1.0 - September 2013 * Initial release. * Tested via unit testing on PHP 5.0
1.1 - February 2014 * Initial Github release. * Sever Bugs reported by Domenic LaRosa fixed. * Tested on PHP 5.5.59 * Added is_resource_custom/get_resource_type_custom functions. * Added unit test for PHP >= 5.5.5 * Fixed some logical issues not tested on PHP >= 5.5.5
1.2 - September 2014 * Fixed an issue (Thanks to Martijn Spruit) where the script was breaking on PHP V <= 5.3.8 * Updated unit test for MySQL_Stat_Test to allow a <= 10 difference between the numbers.
1.3 - October 2019
* When calling a bad instance, a MySQL2PDOException will be thrown instead of a die statement.
* Fixed a bug where it was returning the wrong instance id in
1.4 - October 2019