MySQL Native Driver (
Mysqlnd
)
2549
Calling parent methods
If the original function table entries are backed up, it is still possible to call the original function table
entries - the parent methods.
In some cases, such as for
Connection::stmt_init()
, it is vital to call the parent method prior to
any other activity in the derived method.
MYSQLND_METHOD(my_conn_class, query)(MYSQLND *conn,
const char *query, unsigned int query_len TSRMLS_DC) {
php_printf("my_conn_class::query(query = %s)\n", query);
query = "SELECT 'query rewritten' FROM DUAL";
query_len = strlen(query);
return org_methods.query(conn, query, query_len); /* return with call to parent */
}
Extending properties
A
mysqlnd
object is represented by a C struct. It is not possible to add a member to a C struct at run
time. Users of
mysqlnd
objects cannot simply add properties to the objects.
Arbitrary data (properties) can be added to a
mysqlnd
objects using an appropriate function of the
mysqlnd_plugin_get_plugin_<object>_data()
family. When allocating an object
mysqlnd
reserves space at the end of the object to hold a
void *
pointer to arbitrary data.
mysqlnd
reserves
space for one
void *
pointer per plugin.
The following table shows how to calculate the position of the pointer for a specific plugin:
Table 20.67. Pointer calculations for mysqlnd
Memory address
Contents
0
Beginning of the mysqlnd object C struct
n
End of the mysqlnd object C struct
n + (m x sizeof(void*))
void* to object data of the m-th plugin
If you plan to subclass any of the
mysqlnd
object constructors, which is allowed, you must keep this in
mind!
The following code shows extending properties:
/* any data we want to associate */
typedef struct my_conn_properties {
unsigned long query_counter;
} MY_CONN_PROPERTIES;
/* plugin id */
unsigned int my_plugin_id;
void minit_register_hooks(TSRMLS_D) {
/* obtain unique plugin ID */
my_plugin_id = mysqlnd_plugin_register();
/* snip - see Extending Connection: methods */
}
static MY_CONN_PROPERTIES** get_conn_properties(const MYSQLND *conn TSRMLS_DC) {
MY_CONN_PROPERTIES** props;
props = (MY_CONN_PROPERTIES**)mysqlnd_plugin_get_plugin_connection_data(
conn, my_plugin_id);
if (!props || !(*props)) {
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 ...