- Notifications
You must be signed in to change notification settings - Fork 7.8k
/
Copy pathmysqlnd.h
322 lines (255 loc) · 17.6 KB
/
mysqlnd.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Andrey Hristov <andrey@php.net> |
| Ulf Wendel <uw@php.net> |
| Georg Richter <georg@php.net> |
+----------------------------------------------------------------------+
*/
#ifndefMYSQLND_H
#defineMYSQLND_H
#definePHP_MYSQLND_VERSION "mysqlnd " PHP_VERSION
#defineMYSQLND_VERSION_ID PHP_VERSION_ID
#defineMYSQLND_PLUGIN_API_VERSION 2
/*
This force mysqlnd to do a single (or more depending on amount of data)
non-blocking read() calls before sending a command to the server. Useful
for debugging, if previous function hasn't consumed all the output sent
to it - like stmt_send_long_data() error because the data was larger that
max_allowed_packet_size, and COM_STMT_SEND_LONG_DATA by protocol doesn't
use response packets, thus letting the next command to fail miserably, if
the connector implementor is not aware of this deficiency. Should be off
on production systems, if of course measured performance degradation is not
minimal.
*/
#if defined(A0) &&PHP_DEBUG
#defineMYSQLND_DO_WIRE_CHECK_BEFORE_COMMAND 1
#endif
#ifPHP_DEBUG
#defineMYSQLND_DBG_ENABLED 1
#else
#defineMYSQLND_DBG_ENABLED 0
#endif
#defineMYSQLND_CHARSETS_SANITY_CHECK 0
#ifdefZTS
#include"TSRM.h"
#endif
#include"mysqlnd_portability.h"
#include"mysqlnd_enum_n_def.h"
#include"mysqlnd_structs.h"
#defineMYSQLND_STR_W_LEN(str) str, (sizeof(str) - 1)
/* Library related */
PHPAPIvoidmysqlnd_library_init(void);
PHPAPIvoidmysqlnd_library_end(void);
PHPAPI unsignedintmysqlnd_plugin_register(void);
PHPAPI unsignedintmysqlnd_plugin_register_ex(structst_mysqlnd_plugin_header*plugin);
PHPAPI unsignedintmysqlnd_plugin_count(void);
PHPAPIvoid*mysqlnd_plugin_find(constchar*constname);
PHPAPIvoidmysqlnd_plugin_apply_with_argument(apply_func_arg_tapply_func, void*argument);
#definemysqlnd_restart_psession(conn) ((conn)->data)->m->restart_psession((conn)->data)
#definemysqlnd_end_psession(conn) ((conn)->data)->m->end_psession((conn)->data)
PHPAPIvoidmysqlnd_minfo_print_hash(zval*values);
#definemysqlnd_thread_safe() true
PHPAPIconstMYSQLND_CHARSET*mysqlnd_find_charset_nr(constunsigned intcharsetno);
PHPAPIconstMYSQLND_CHARSET*mysqlnd_find_charset_name(constchar*constcharsetname);
/* Connect */
#definemysqlnd_init(flags, persistent) mysqlnd_connection_init((flags), (persistent), NULL /*use default factory*/)
#definemysqlnd_connect(conn, host, user, pass, pass_len, db, db_len, port, socket, mysql_flags, client_api_flags) \
mysqlnd_connection_connect((conn), (host), (user), (pass), (pass_len), (db), (db_len), (port), (socket), (mysql_flags), (client_api_flags))
PHPAPIMYSQLND*mysqlnd_connection_init(constsize_tclient_flags, constboolpersistent, MYSQLND_CLASS_METHODS_TYPE(mysqlnd_object_factory) *object_factory);
PHPAPIMYSQLND*mysqlnd_connection_connect(MYSQLND*conn,
constchar*consthost,
constchar*constuser,
constchar*constpasswd, unsigned intpasswd_len,
constchar*constdb, unsigned intdb_len,
unsigned intport,
constchar*constsocket_or_pipe,
unsigned intmysql_flags,
unsigned intclient_api_flags
);
#definemysqlnd_change_user(conn, user, passwd, db, silent) ((conn)->data)->m->change_user((conn)->data, (user), (passwd), (db), (silent), strlen((passwd)))
#definemysqlnd_change_user_ex(conn, user, passwd, db, silent, passwd_len) ((conn)->data)->m->change_user((conn)->data, (user), (passwd), (db), (silent), (passwd_len))
PHPAPIvoidmysqlnd_debug(constchar*mode);
/* Query */
#definemysqlnd_fetch_into(result, flags, ret_val) (result)->m.fetch_into((result), (flags), (ret_val) ZEND_FILE_LINE_CC)
#definemysqlnd_fetch_row_c(result) (result)->m.fetch_row_c((result))
#definemysqlnd_fetch_row_zval(result, row_ptr, fetched) \
(result)->m.fetch_row((result), (row_ptr), 0, (fetched))
#definemysqlnd_get_connection_stats(conn, values) ((conn)->data)->m->get_statistics((conn)->data, (values) ZEND_FILE_LINE_CC)
#definemysqlnd_get_client_stats(values) _mysqlnd_get_client_stats(mysqlnd_global_stats, (values) ZEND_FILE_LINE_CC)
#definemysqlnd_close(conn,is_forced) (conn)->m->close((conn), (is_forced))
#definemysqlnd_query(conn, query_str, query_len) ((conn)->data)->m->query((conn)->data, (query_str), (query_len))
#definemysqlnd_async_query(conn, query_str, query_len) ((conn)->data)->m->send_query((conn)->data, (query_str), (query_len), NULL, NULL)
#definemysqlnd_reap_async_query(conn) ((conn)->data)->m->reap_query((conn)->data)
PHPAPIenum_func_statusmysqlnd_poll(MYSQLND**r_array, MYSQLND**e_array, MYSQLND***dont_poll, longsec, longusec, int*desc_num);
#definemysqlnd_use_result(conn) ((conn)->data)->m->use_result((conn)->data)
#definemysqlnd_store_result(conn) ((conn)->data)->m->store_result((conn)->data)
#definemysqlnd_next_result(conn) ((conn)->data)->m->next_result((conn)->data)
#definemysqlnd_more_results(conn) ((conn)->data)->m->more_results((conn)->data)
#definemysqlnd_free_result(r,e_or_i) ((MYSQLND_RES*)r)->m.free_result(((MYSQLND_RES*)(r)), (e_or_i))
#definemysqlnd_data_seek(result, row) (result)->m.seek_data((result), (row))
/* Errors */
#definemysqlnd_errno(conn) ((conn)->data)->m->get_error_no((conn)->data)
#definemysqlnd_error(conn) ((conn)->data)->m->get_error_str((conn)->data)
#definemysqlnd_sqlstate(conn) ((conn)->data)->m->get_sqlstate((conn)->data)
/* Charset */
#definemysqlnd_character_set_name(conn) ((conn)->data)->m->charset_name((conn)->data)
/* Simple metadata */
#definemysqlnd_field_count(conn) ((conn)->data)->m->get_field_count((conn)->data)
#definemysqlnd_insert_id(conn) ((conn)->data)->m->get_last_insert_id((conn)->data)
#definemysqlnd_affected_rows(conn) ((conn)->data)->m->get_affected_rows((conn)->data)
#definemysqlnd_warning_count(conn) ((conn)->data)->m->get_warning_count((conn)->data)
#definemysqlnd_info(conn) ((conn)->data)->m->get_last_message((conn)->data)
#definemysqlnd_get_server_info(conn) ((conn)->data)->m->get_server_information((conn)->data)
#definemysqlnd_get_server_version(conn) ((conn)->data)->m->get_server_version((conn)->data)
#definemysqlnd_get_host_info(conn) ((conn)->data)->m->get_host_information((conn)->data)
#definemysqlnd_get_proto_info(conn) ((conn)->data)->m->get_protocol_information((conn)->data)
#definemysqlnd_thread_id(conn) ((conn)->data)->m->get_thread_id((conn)->data)
#definemysqlnd_get_server_status(conn) ((conn)->data)->m->get_server_status((conn)->data)
#definemysqlnd_num_rows(result) (result)->m.num_rows((result))
#definemysqlnd_num_fields(result) (result)->m.num_fields((result))
#definemysqlnd_fetch_lengths(result) (result)->m.fetch_lengths((result))
#definemysqlnd_field_seek(result, ofs) (result)->m.seek_field((result), (ofs))
#definemysqlnd_field_tell(result) (result)->m.field_tell((result))
#definemysqlnd_fetch_field(result) (result)->m.fetch_field((result))
#definemysqlnd_fetch_field_direct(result,fnr) (result)->m.fetch_field_direct((result), (fnr))
#definemysqlnd_fetch_fields(result) (result)->m.fetch_fields((result))
/* mysqlnd metadata */
PHPAPIconstchar*mysqlnd_get_client_info(void);
PHPAPI unsigned longmysqlnd_get_client_version(void);
#definemysqlnd_ssl_set(conn, key, cert, ca, capath, cipher) ((conn)->data)->m->ssl_set((conn)->data, (key), (cert), (ca), (capath), (cipher))
/* PS */
#definemysqlnd_stmt_insert_id(stmt) (stmt)->m->get_last_insert_id((stmt))
#definemysqlnd_stmt_affected_rows(stmt) (stmt)->m->get_affected_rows((stmt))
#definemysqlnd_stmt_num_rows(stmt) (stmt)->m->get_num_rows((stmt))
#definemysqlnd_stmt_param_count(stmt) (stmt)->m->get_param_count((stmt))
#definemysqlnd_stmt_field_count(stmt) (stmt)->m->get_field_count((stmt))
#definemysqlnd_stmt_warning_count(stmt) (stmt)->m->get_warning_count((stmt))
#definemysqlnd_stmt_server_status(stmt) (stmt)->m->get_server_status((stmt))
#definemysqlnd_stmt_errno(stmt) (stmt)->m->get_error_no((stmt))
#definemysqlnd_stmt_error(stmt) (stmt)->m->get_error_str((stmt))
#definemysqlnd_stmt_sqlstate(stmt) (stmt)->m->get_sqlstate((stmt))
PHPAPIvoidmysqlnd_efree_param_bind_dtor(MYSQLND_PARAM_BIND*param_bind);
PHPAPIvoidmysqlnd_efree_result_bind_dtor(MYSQLND_RESULT_BIND*result_bind);
PHPAPIvoidmysqlnd_free_param_bind_dtor(MYSQLND_PARAM_BIND*param_bind);
PHPAPIvoidmysqlnd_free_result_bind_dtor(MYSQLND_RESULT_BIND*result_bind);
/* LOAD DATA LOCAL */
PHPAPIvoidmysqlnd_local_infile_default(MYSQLND_CONN_DATA*conn);
/* Simple commands */
#definemysqlnd_autocommit(conn, mode) ((conn)->data)->m->set_autocommit((conn)->data, (mode))
#definemysqlnd_begin_transaction(conn,flags,name) ((conn)->data)->m->tx_begin((conn)->data, (flags), (name))
#definemysqlnd_commit(conn, flags, name) ((conn)->data)->m->tx_commit_or_rollback((conn)->data, true, (flags), (name))
#definemysqlnd_rollback(conn, flags, name) ((conn)->data)->m->tx_commit_or_rollback((conn)->data, false, (flags), (name))
#definemysqlnd_savepoint(conn, name) ((conn)->data)->m->tx_savepoint((conn)->data, (name))
#definemysqlnd_release_savepoint(conn, name) ((conn)->data)->m->tx_savepoint_release((conn)->data, (name))
#definemysqlnd_list_dbs(conn, wild) ((conn)->data)->m->list_method((conn)->data, wild? "SHOW DATABASES LIKE %s":"SHOW DATABASES", (wild), NULL)
#definemysqlnd_list_processes(conn) ((conn)->data)->m->list_method((conn)->data, "SHOW PROCESSLIST", NULL, NULL)
#definemysqlnd_list_tables(conn, wild) ((conn)->data)->m->list_method((conn)->data, wild? "SHOW TABLES LIKE %s":"SHOW TABLES", (wild), NULL)
#definemysqlnd_dump_debug_info(conn) ((conn)->data)->m->server_dump_debug_information((conn)->data)
#definemysqlnd_select_db(conn, db, db_len) ((conn)->data)->m->select_db((conn)->data, (db), (db_len))
#definemysqlnd_ping(conn) ((conn)->data)->m->ping((conn)->data)
#definemysqlnd_kill(conn, pid) ((conn)->data)->m->kill_connection((conn)->data, (pid))
#definemysqlnd_refresh(conn, options) ((conn)->data)->m->refresh_server((conn)->data, (options))
#definemysqlnd_set_character_set(conn, cs) ((conn)->data)->m->set_charset((conn)->data, (cs))
#definemysqlnd_stat(conn, msg) ((conn)->data)->m->get_server_statistics(((conn)->data), (msg))
#definemysqlnd_options(conn, opt, value) ((conn)->data)->m->set_client_option((conn)->data, (opt), (value))
#definemysqlnd_options4(conn, opt, k, v) ((conn)->data)->m->set_client_option_2d((conn)->data, (opt), (k), (v))
#definemysqlnd_set_server_option(conn, op) ((conn)->data)->m->set_server_option((conn)->data, (op))
/* Escaping */
#definemysqlnd_real_escape_string(conn, newstr, escapestr, escapestr_len) \
((conn)->data)->m->escape_string((conn)->data, (newstr), (escapestr), (escapestr_len))
#definemysqlnd_escape_string(newstr, escapestr, escapestr_len) \
mysqlnd_old_escape_string((newstr), (escapestr), (escapestr_len))
PHPAPIzend_ulongmysqlnd_old_escape_string(char*newstr, constchar*escapestr, size_tescapestr_len);
/* PS */
#definemysqlnd_stmt_init(conn) ((conn)->data)->m->stmt_init(((conn)->data))
#definemysqlnd_stmt_store_result(stmt) (!mysqlnd_stmt_field_count((stmt)) ? PASS:((stmt)->m->store_result((stmt))? PASS:FAIL))
#definemysqlnd_stmt_get_result(stmt) (stmt)->m->get_result((stmt))
#definemysqlnd_stmt_more_results(stmt) (stmt)->m->more_results((stmt))
#definemysqlnd_stmt_next_result(stmt) (stmt)->m->next_result((stmt))
#definemysqlnd_stmt_data_seek(stmt, row) (stmt)->m->seek_data((stmt), (row))
#definemysqlnd_stmt_prepare(stmt, q, qlen) (stmt)->m->prepare((stmt), (q), (qlen))
#definemysqlnd_stmt_execute(stmt) (stmt)->m->execute((stmt))
#definemysqlnd_stmt_send_long_data(stmt,p,d,l) (stmt)->m->send_long_data((stmt), (p), (d), (l))
#definemysqlnd_stmt_alloc_param_bind(stmt) (stmt)->m->alloc_parameter_bind((stmt))
#definemysqlnd_stmt_free_param_bind(stmt,bind) (stmt)->m->free_parameter_bind((stmt), (bind))
#definemysqlnd_stmt_bind_param(stmt,bind) (stmt)->m->bind_parameters((stmt), (bind))
#definemysqlnd_stmt_bind_one_param(stmt,n,z,t) (stmt)->m->bind_one_parameter((stmt), (n), (z), (t))
#definemysqlnd_stmt_refresh_bind_param(s) (s)->m->refresh_bind_param((s))
#definemysqlnd_stmt_alloc_result_bind(stmt) (stmt)->m->alloc_result_bind((stmt))
#definemysqlnd_stmt_free_result_bind(stmt,bind) (stmt)->m->free_result_bind((stmt), (bind))
#definemysqlnd_stmt_bind_result(stmt,bind) (stmt)->m->bind_result((stmt), (bind))
#definemysqlnd_stmt_bind_one_result(s,no) (s)->m->bind_one_result((s), (no))
#definemysqlnd_stmt_result_metadata(stmt) (stmt)->m->get_result_metadata((stmt))
#definemysqlnd_stmt_free_result(stmt) (stmt)->m->free_result((stmt))
#definemysqlnd_stmt_close(stmt, implicit) (stmt)->m->dtor((stmt), (implicit))
#definemysqlnd_stmt_reset(stmt) (stmt)->m->reset((stmt))
#definemysqlnd_stmt_flush(stmt) (stmt)->m->flush((stmt))
#definemysqlnd_stmt_attr_get(stmt, attr, value) (stmt)->m->get_attribute((stmt), (attr), (value))
#definemysqlnd_stmt_attr_set(stmt, attr, value) (stmt)->m->set_attribute((stmt), (attr), (value))
#definemysqlnd_stmt_fetch(stmt, fetched) (stmt)->m->fetch((stmt), (fetched))
/* Performance statistics */
PHPAPIexternMYSQLND_STATS*mysqlnd_global_stats;
PHPAPIexternconstMYSQLND_STRINGmysqlnd_stats_values_names[];
PHPAPIvoid_mysqlnd_get_client_stats(MYSQLND_STATS*stats, zval*return_valueZEND_FILE_LINE_DC);
#ifndefMYSQLND_CORE_STATISTICS_DISABLED
#defineMYSQLND_INC_GLOBAL_STATISTIC(statistic) \
MYSQLND_INC_STATISTIC(MYSQLND_G(collect_statistics), mysqlnd_global_stats, (statistic))
#defineMYSQLND_DEC_GLOBAL_STATISTIC(statistic) \
MYSQLND_DEC_STATISTIC(MYSQLND_G(collect_statistics), mysqlnd_global_stats, (statistic))
#defineMYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(statistic1, value1, statistic2, value2) \
MYSQLND_INC_STATISTIC_W_VALUE2(MYSQLND_G(collect_statistics), mysqlnd_global_stats, (statistic1), (value1), (statistic2), (value2))
#defineMYSQLND_INC_CONN_STATISTIC(conn_stats, statistic) \
MYSQLND_INC_STATISTIC(MYSQLND_G(collect_statistics), mysqlnd_global_stats, (statistic)); \
MYSQLND_INC_STATISTIC(MYSQLND_G(collect_statistics), (conn_stats), (statistic));
#defineMYSQLND_INC_CONN_STATISTIC_W_VALUE(conn_stats, statistic, value) \
MYSQLND_INC_STATISTIC_W_VALUE(MYSQLND_G(collect_statistics), mysqlnd_global_stats, (statistic), (value)); \
MYSQLND_INC_STATISTIC_W_VALUE(MYSQLND_G(collect_statistics), (conn_stats), (statistic), (value));
#defineMYSQLND_INC_CONN_STATISTIC_W_VALUE2(conn_stats, statistic1, value1, statistic2, value2) \
MYSQLND_INC_STATISTIC_W_VALUE2(MYSQLND_G(collect_statistics), mysqlnd_global_stats, (statistic1), (value1), (statistic2), (value2)); \
MYSQLND_INC_STATISTIC_W_VALUE2(MYSQLND_G(collect_statistics), (conn_stats), (statistic1), (value1), (statistic2), (value2));
#defineMYSQLND_INC_CONN_STATISTIC_W_VALUE3(conn_stats, statistic1, value1, statistic2, value2, statistic3, value3) \
MYSQLND_INC_STATISTIC_W_VALUE3(MYSQLND_G(collect_statistics), mysqlnd_global_stats, (statistic1), (value1), (statistic2), (value2), (statistic3), (value3)); \
MYSQLND_INC_STATISTIC_W_VALUE3(MYSQLND_G(collect_statistics), (conn_stats), (statistic1), (value1), (statistic2), (value2), (statistic3), (value3));
#else
#defineMYSQLND_INC_GLOBAL_STATISTIC(statistic)
#defineMYSQLND_DEC_GLOBAL_STATISTIC(statistic)
#defineMYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(statistic1, value1, statistic2, value2)
#defineMYSQLND_INC_CONN_STATISTIC(conn_stats, statistic)
#defineMYSQLND_INC_CONN_STATISTIC_W_VALUE(conn_stats, statistic, value)
#defineMYSQLND_INC_CONN_STATISTIC_W_VALUE2(conn_stats, statistic1, value1, statistic2, value2)
#defineMYSQLND_INC_CONN_STATISTIC_W_VALUE3(conn_stats, statistic1, value1, statistic2, value2, statistic3, value3)
#endif/* MYSQLND_CORE_STATISTICS_DISABLED */
/* double check the class name to avoid naming conflicts when using these: */
#defineMYSQLND_METHOD(class, method) mysqlnd_##class##_##method##_pub
#defineMYSQLND_METHOD_PRIVATE(class, method) mysqlnd_##class##_##method##_priv
ZEND_BEGIN_MODULE_GLOBALS(mysqlnd)
char*debug; /* The actual string */
char*trace_alloc_settings; /* The actual string */
MYSQLND_DEBUG*dbg; /* The DBG object for standard tracing */
MYSQLND_DEBUG*trace_alloc; /* The DBG object for allocation tracing */
zend_longnet_cmd_buffer_size;
zend_longnet_read_buffer_size;
zend_longlog_mask;
zend_longnet_read_timeout;
zend_longmempool_default_size;
char*sha256_server_public_key;
boolcollect_statistics;
boolcollect_memory_statistics;
ZEND_END_MODULE_GLOBALS(mysqlnd)
PHPAPIZEND_EXTERN_MODULE_GLOBALS(mysqlnd)
#defineMYSQLND_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(mysqlnd, v)
#if defined(ZTS) && defined(COMPILE_DL_MYSQLND)
ZEND_TSRMLS_CACHE_EXTERN()
#endif
PHPAPIvoidmysqlnd_minfo_print_hash(zval*values);
#endif/* MYSQLND_H */