MySQL Native Driver (
Mysqlnd
)
2548
At the code level,
mysqlnd
uses a C pattern for implementing object orientation.
In C you use a
struct
to represent an object. Members of the struct represent object properties.
Struct members pointing to functions represent methods.
Unlike with other languages such as C++ or Java, there are no fixed rules on inheritance in the C
object oriented paradigm. However, there are some conventions that need to be followed that will be
discussed later.
The PHP Life Cycle
When considering the PHP life cycle there are two basic cycles:
• PHP engine startup and shutdown cycle
• Request cycle
When the PHP engine starts up it will call the module initialization (MINIT) function of each registered
extension. This allows each module to setup variables and allocate resources that will exist for the
lifetime of the PHP engine process. When the PHP engine shuts down it will call the module shutdown
(MSHUTDOWN) function of each extension.
During the lifetime of the PHP engine it will receive a number of requests. Each request constitutes
another life cycle. On each request the PHP engine will call the request initialization function of each
extension. The extension can perform any variable setup and resource allocation required for request
processing. As the request cycle ends the engine calls the request shutdown (RSHUTDOWN) function
of each extension so the extension can perform any cleanup required.
How a plugin works
A
mysqlnd
plugin works by intercepting calls made to
mysqlnd
by extensions that use
mysqlnd
.
This is achieved by obtaining the
mysqlnd
function table, backing it up, and replacing it by a custom
function table, which calls the functions of the plugin as required.
The following code shows how the
mysqlnd
function table is replaced:
/* a place to store original function table */
struct st_mysqlnd_conn_methods org_methods;
void minit_register_hooks(TSRMLS_D) {
/* active function table */
struct st_mysqlnd_conn_methods * current_methods
= mysqlnd_conn_get_methods();
/* backup original function table */
memcpy(&org_methods, current_methods,
sizeof(struct st_mysqlnd_conn_methods);
/* install new methods */
current_methods->query = MYSQLND_METHOD(my_conn_class, query);
}
Connection function table manipulations must be done during Module Initialization (MINIT). The
function table is a global shared resource. In an multi-threaded environment, with a TSRM build, the
manipulation of a global shared resource during the request processing will almost certainly result in
conflicts.
Note
Do not use any fixed-size logic when manipulating the
mysqlnd
function table:
new methods may be added at the end of the function table. The function table
may change at any time in the future.
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...