**In brief**  

We need to switch from mysqli to mysql. We want a wrapper class which uses PHP's mysql extension's functions but supports the functionality of the following functions of mysqli - 

```
query(), real_escape_string(), multi_query(), store_result(), more_results() , next_result(), use_result(), mysqli_connect_error().  

```

E.g. using mysql\_pconnect() for persistent connections.

Basically, it would be making sure we have the same logic and return types for all the functions, we will have to verify against the documentations of all the concerned functions and will probably have to look into the implementation of mysqli functions too.

But, has anybody come up with something similar?

**Background**  

We use [Tera-WURFL](http://dbapi.scientiamobile.com/wiki/index.php/Main_Page) in our system for mobile device detection. We faced some problems because our production PHP version was 5.2.6 and TeraWurfl uses a database connector TeraWurflDatabase\_MySQL5.php which uses the following things:

* mysqli\_connect\_error(), which is not supported until php 5.2.9 ( we use php 5.2.6 )
* persistent connections which are not supported until php 5.3.0 ( we use php 5.2.6 )

mysqli is not fully supported until php 5.3.0.

So, we have two options -

1. Upgrade PHP - But, that would require significant amount of Regression testing since the OpenX version that we are using does not seem to have tested against these latest PHP versions. Our system's core lies around Openx.
2. Write a wrapper class to have the same Object oriented API as that of MySQLi. This is looking simpler.

So, we have decided to estimate the effort needed to come up with a wrapper class. Here is what we thought - 

Since PHP provides only procedural interface for its mysql extension and `TeraWurflDatabase_MySQL5.php` calls mysqli's functions in an object oriented manner, we will have to create a wrapper class which will provide the same interface as the mysqli class, in order to switch to mysql.

We can create functions with the same names as in mysqli e.g. query(), store\_result() and return similar parameters so that we only have to change the object initiation in `TeraWurflDatabase_MySQL5.php` file.

Has anybody done this?