Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 9819

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>How it works</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mysqlnd-uh.quickstart.configuration.html">Setup</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mysqlnd-uh.quickstart.proxy-installation.html">Installing a proxy</a></div>
 <div class="up"><a href="mysqlnd-uh.quickstart.html">Quickstart and Examples</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="mysqlnd-uh.quickstart.how-it-works" class="section">
  <h2 class="title">How it works</h2>
  <p class="para">
   This describes the background and inner workings of the mysqlnd_uh
   extension.
  </p>
  <p class="para">
   Two classes are provided by the extension: <a href="class.mysqlnduhconnection.html" class="classname">MysqlndUhConnection</a>
   and <a href="class.mysqlnduhpreparedstatement.html" class="classname">MysqlndUhPreparedStatement</a>. <a href="class.mysqlnduhconnection.html" class="classname">MysqlndUhConnection</a> lets
   you access almost all methods of the <em>mysqlnd</em>
   internal <em>connection</em> class. The latter exposes some selected
   methods of the  <em>mysqlnd</em> internal <em>statement</em> class.
   For example,  <span class="methodname"><a href="mysqlnduhconnection.connect.html" class="methodname">MysqlndUhConnection::connect()</a></span> maps to
   the <em>mysqlnd</em> library C function
   <em>mysqlnd_conn__connect</em>.
  </p>
  <p class="para">
   As a mysqlnd plugin, the PECL/mysqlnd_uh extension replaces <em>mysqlnd</em>
   library C functions with its own functions. Whenever a
   PHP MySQL extension compiled to use <em>mysqlnd</em> calls
   a mysqlnd function, the functions installed by the plugin are executed
   instead of the original <em>mysqlnd</em> ones. For example,
    <span class="function"><a href="function.mysqli-connect.html" class="function">mysqli_connect()</a></span> invokes <em>mysqlnd_conn__connect</em>,
   so the connect function installed by PECL/mysqlnd_uh will be called.
   The functions installed by PECL/mysqlnd_uh are the methods of the built-in classes.
  </p>
  <p class="para">
   The built-in PHP classes and their methods do nothing but call their
   <em>mysqlnd</em> C library counterparts, to behave exactly
   like the original <em>mysqlnd</em> function they replace.
   The code below illustrates in pseudo-code what the extension does.
  </p>
  <p class="para">
   <div class="example" id="example-1871">
    <p><strong>Example #1 Pseudo-code: what a built-in class does</strong></p>
    <div class="example-contents">
<div class="cdata"><pre>
class MysqlndUhConnection {
  public function connect(($conn, $host, $user, $passwd, $db, $port, $socket, $mysql_flags) {
    MYSQLND* c_mysqlnd_connection = convert_from_php_to_c($conn);
    ...
    return call_c_function(mysqlnd_conn__connect(c_mysqlnd_connection, ...));
  }
}
</pre></div>
    </div>

    </div>
  </p>
  <p class="para">
   The build-in classes behave like a transparent proxy. It is possible for
   you to replace the proxy with your own. This is done by subclassing
   <a href="class.mysqlnduhconnection.html" class="classname">MysqlndUhConnection</a> or
   <a href="class.mysqlnduhpreparedstatement.html" class="classname">MysqlndUhPreparedStatement</a> to extend the functionality
   of the proxy, followed by registering a new proxy object.
   Proxy objects are installed by
    <span class="function"><a href="function.mysqlnd-uh-set-connection-proxy.html" class="function">mysqlnd_uh_set_connection_proxy()</a></span>
   and
    <span class="function"><a href="function.mysqlnd-uh-set-statement-proxy.html" class="function">mysqlnd_uh_set_statement_proxy()</a></span>.
  </p>
  <p class="para">
   <div class="example" id="example-1872">
    <p><strong>Example #2 Installing a proxy</strong></p>
        <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">proxy&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">MysqlndUhConnection&nbsp;</span><span style="color: #007700">{<br />&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$host</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$user</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$passwd</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$db</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$port</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$socket</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$mysql_flags</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%s(%s)\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">__METHOD__</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">func_get_args</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$ret&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">parent</span><span style="color: #007700">::</span><span style="color: #0000BB">connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$host</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$user</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$passwd</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$db</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$port</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$socket</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$mysql_flags</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%s&nbsp;returns&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">__METHOD__</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">$ret</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$ret</span><span style="color: #007700">;<br />&nbsp;}<br />}<br /></span><span style="color: #0000BB">mysqlnd_uh_set_connection_proxy</span><span style="color: #007700">(new&nbsp;</span><span style="color: #0000BB">proxy</span><span style="color: #007700">());<br /><br /></span><span style="color: #0000BB">$mysqli&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"root"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"test"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
proxy::connect(array (
  0 =&gt; NULL,
  1 =&gt; &#039;localhost&#039;,
  2 =&gt; &#039;root&#039;,
  3 =&gt; &#039;&#039;,
  4 =&gt; &#039;test&#039;,
  5 =&gt; 3306,
  6 =&gt; NULL,
  7 =&gt; 131072,
))
proxy::connect returns true
</pre></div>
    </div>
   </div>
  </p>
 </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mysqlnd-uh.quickstart.configuration.html">Setup</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mysqlnd-uh.quickstart.proxy-installation.html">Installing a proxy</a></div>
 <div class="up"><a href="mysqlnd-uh.quickstart.html">Quickstart and Examples</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>