PHPackages                             matthewbaggett/mysql2pdo - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. matthewbaggett/mysql2pdo

ActiveLibrary[Database &amp; ORM](/categories/database)

matthewbaggett/mysql2pdo
========================

MySQL2PDO adaptor

3111PHP

Since Jul 27Pushed 10y ago1 watchersCompare

[ Source](https://github.com/matthewbaggett/MySQL2PDO)[ Packagist](https://packagist.org/packages/matthewbaggett/mysql2pdo)[ RSS](/packages/matthewbaggett-mysql2pdo/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

mysql methods using PDO
=======================

[](#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.

Implementation:
---------------

[](#implementation)

In your bootstrap, include:

```
// Include the definitions
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MySQL_Definitions.php');

// Include the object
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MySQL.php');

// Include the mysql_* functions
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MySQL_Functions.php');

// Now all of the mysql_* methods will work on a PHP version that has them removed.

```

(OPTIONAL : SEE DRAWBACKS) Update your error reporting to (depending on environment):

```
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT); // Production
error_reporting(E_ALL & ~E_STRICT); // Development

```

(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:

```
find ./ -type f | xargs sed -i 's/is_resource( /is_resource_custom(/'
find ./ -type f | xargs sed -i 's/get_resource_type( /get_resource_type_custom(/'

```

Who is this for?
----------------

[](#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 were the mysql extension removed?
-------------------------------------

[](#why-were-the-mysql-extension-removed)

Lack of:

- Stored Procedures (can’t handle multiple result sets)
- Prepared Statements
- Encryption (SSL)
- Compression
- Full Charset support
- Security

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.

Alternative host:
-----------------

[](#alternative-host)

This project can also be found on phpclasses.org:

and GitHub:

I will try my best to keep them updated.

Drawbacks of this library
=========================

[](#drawbacks-of-this-library)

Unfortunately due to limitations, there are some things you should know before implementing this library.

Resources
---------

[](#resources)

Since it is not possible to create resources on the fly in PHP. The following methods will not work as intended:

is\_resource get\_resource\_type

on the following mysql functions:

```
Function Name (resource type) (our library type)
mysql_connect (mysql link) (int)
mysql_pconnect (mysql link persistent) (int)
mysql_db_query (mysql result) (PDO Statement)
mysql_list_dbs (mysql result) (PDO Statement)
mysql_list_fields (mysql result) (PDO Statement)
mysql_list_processors (mysql result) (PDO Statement)
mysql_list_dbs (mysql result) (PDO Statement)
mysql_query (mysql result) (PDO Statement)
mysql_unbuffered_query (mysql result) (PDO Statement)

```

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:

```
find ./ -type f | xargs sed -i 's/is_resource( /is_resource_custom(/'
find ./ -type f | xargs sed -i 's/get_resource_type( /get_resource_type_custom(/'

```

Error Reporting
---------------

[](#error-reporting)

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(&gt;= 30720)):

```
mysql_fetch_array
mysql_fetch_assoc
mysql_fetch_row
mysql_fetch_object
mysql_db_name
mysql_dbname
mysql_tablename
mysql_result
mysql_free_result
mysql_freeresult
mysql_field_len
mysql_fieldlen
mysql_field_flags
mysql_fieldflags
mysql_field_name
mysql_fieldname
mysql_field_type
mysql_fieldtype
mysql_field_table
mysql_fieldtable
mysql_field_seek
mysql_fetch_field

```

To fix, you will need to change your error reporting hide strict standards (anything &lt;= 30719). Examples:

```
error_reporting(30719); //
