Reputation: 10294
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 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 is not fully supported until php 5.3.0.
So, we have two options -
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.
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?
Upvotes: 2
Views: 1355
Reputation: 2992
OpenX 2.8.10 works in PHP 5.4 if you do the following changes:
A) in /openx2.8.10/lib/pear/PEAR.php change the following (line 335)
function setErrorHandling($mode = null, $options = null)
to
public static function setErrorHandling($mode = null, $options = null)
B) in openx2.8.10/lib/OA/Admin/Statistics/Delivery/CommonEntity.php change the following (line 294)
$oPlugin->mergeAds($this->childrendata['ad_id']);
to
$oPlugin->mergeAds(&$this->childrendata['ad_id']);
C) in openx2.8.10/lib/OA/Admin/Statistics/Delivery/CommonEntity.php change the following (line 324)
$oPlugin->mergeZones($this->childrendata['zone_id']);
to
$oPlugin->mergeZones(&$this->childrendata['zone_id']);
With this changes OpenX and its stadistics page will be available in PHP 5.4
Upvotes: 0
Reputation: 1471
maybe give a try to Zebra_Database a lightweight mysql database wrapper - one file only, mature and very well documented
Upvotes: 0
Reputation: 4560
First of all at least upgrade to latest 5.2.x release - it's fully compatible with your 5.2.6 which is btw 4 years old now and has 4 years worth of unfixed bugs, including security issues.
Secondly mysqli introduces many features unsupported by mysql extension that you will not be able to get around with a wrapper. If your php code uses prepared statements, multiple statements or transactions wrapper will not do.
Btw OpenX seems to work with PHP 5.3 if you apply this fix: http://www.outofcontrol.ca/thoughts/comments/openx-causing-segmentation-fault-11-in-php-5-3-6 it doesn't work with PHP 5.4 and I seriously doubt it ever will, since open source version doesn't seem to be developed anymore.
Upvotes: 2
Reputation: 2769
Have you tried PDO? Since you use php 5.2 and from the manual "PDO ships with PHP 5.1, and is available as a PECL extension for PHP 5.0"
Upvotes: 0