title: Having a Mysql wrapper class to support few functions of mysqli
body: <p><strong>In brief</strong><br>
  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 - </p>
  
  <pre><code>query(), real_escape_string(), multi_query(), store_result(), more_results() , next_result(), use_result(), mysqli_connect_error().  
  </code></pre>
  
  <p>E.g. using mysql_pconnect() for persistent connections.</p>
  
  <p>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.</p>
  
  <p>But, has anybody come up with something similar?</p>
  
  <p><strong>Background</strong><br>
  We use <a href="http://dbapi.scientiamobile.com/wiki/index.php/Main_Page" rel="nofollow">Tera-WURFL</a> 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:</p>
  
  <ul>
  <li>mysqli_connect_error(), which is not supported until php 5.2.9 ( we use php 5.2.6 )</li>
  <li>persistent connections which are not supported until php 5.3.0 ( we use php 5.2.6 )</li>
  </ul>
  
  <p>mysqli is not fully supported until php 5.3.0.</p>
  
  <p>So, we have two options -</p>
  
  <ol>
  <li><p>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.</p></li>
  <li><p>Write a wrapper class to have the same Object oriented API as that of MySQLi. This is looking simpler.</p></li>
  </ol>
  
  <p>So, we have decided to estimate the effort needed to come up with a wrapper class. Here is what we thought - </p>
  
  <p>Since PHP provides only procedural interface for its mysql extension and <code>TeraWurflDatabase_MySQL5.php</code> 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.</p>
  
  <p>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 <code>TeraWurflDatabase_MySQL5.php</code> file.</p>
  
  <p>Has anybody done this?</p>