MySQL Native Driver (
Mysqlnd
)
2553
ext/mysqlnd_cache
mysqlnd_cache.query()
1. mysqlnd_cache.query()
2. mysqlnd.query
ext/mysqlnd_monitor
mysqlnd_monitor.query()
1. mysqlnd_monitor.query()
2. mysqlnd_cache.query()
3. mysqlnd.query
In this scenario, a cache (
ext/mysqlnd_cache
) and a monitor (
ext/mysqlnd_monitor
) plugin are
loaded. Both subclass
Connection::query()
. Plugin registration happens at
MINIT
using the logic
shown previously. PHP calls extensions in alphabetical order by default. Plugins are not aware of each
other and do not set extension dependencies.
By default the plugins call the parent implementation of the query method in their derived version of the
method.
PHP Extension Recap
This is a recap of what happens when using an example plugin,
ext/mysqlnd_plugin
, which
exposes the
mysqlnd
C plugin API to PHP:
• Any PHP MySQL application tries to establish a connection to 192.168.2.29
• The PHP application will either use
ext/mysql
,
ext/mysqli
or
PDO_MYSQL
. All three PHP MySQL
extensions use
mysqlnd
to establish the connection to 192.168.2.29.
•
Mysqlnd
calls its connect method, which has been subclassed by
ext/mysqlnd_plugin
.
•
ext/mysqlnd_plugin
calls the userspace hook
proxy::connect()
registered by the user.
• The userspace hook changes the connection host IP from 192.168.2.29 to 127.0.0.1 and returns the
connection established by
parent::connect()
.
•
ext/mysqlnd_plugin
performs the equivalent of
parent::connect(127.0.0.1)
by calling the
original
mysqlnd
method for establishing a connection.
•
ext/mysqlnd
establishes a connection and returns to
ext/mysqlnd_plugin
.
ext/
mysqlnd_plugin
returns as well.
• Whatever PHP MySQL extension had been used by the application, it receives a connection to
127.0.0.1. The PHP MySQL extension itself returns to the PHP application. The circle is closed.
20.7.5.7.5. Getting started building a mysqlnd plugin
Copyright 1997-2012 the PHP Documentation Group. [2230]
It is important to remember that a
mysqlnd
plugin is itself a PHP extension.
The following code shows the basic structure of the MINIT function that will be used in the typical
mysqlnd
plugin:
/* my_php_mysqlnd_plugin.c */
static PHP_MINIT_FUNCTION(mysqlnd_plugin) {
/* globals, ini entries, resources, classes */
/* register mysqlnd plugin */
mysqlnd_plugin_id = mysqlnd_plugin_register();
conn_m = mysqlnd_get_conn_methods();
memcpy(org_conn_m, conn_m,
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...