1 /* 2 +----------------------------------------------------------------------+ 3 | PHP Version 5 | 4 +----------------------------------------------------------------------+ 5 | Copyright (c) 2006-2013 The PHP Group | 6 +----------------------------------------------------------------------+ 7 | This source file is subject to version 3.01 of the PHP license, | 8 | that is bundled with this package in the file LICENSE, and is | 9 | available through the world-wide-web at the following url: | 10 | http://www.php.net/license/3_01.txt | 11 | If you did not receive a copy of the PHP license and are unable to | 12 | obtain it through the world-wide-web, please send a note to | 13 | license@php.net so we can mail you a copy immediately. | 14 +----------------------------------------------------------------------+ 15 | Authors: Georg Richter <georg@mysql.com> | 16 | Andrey Hristov <andrey@mysql.com> | 17 | Ulf Wendel <uwendel@mysql.com> | 18 +----------------------------------------------------------------------+ 19 */ 20 /* $Id: 731e5b87ba42146a687c29995d2dfd8b4e40b325 $ */ 21 22 #ifndef MYSQLND_H 23 #define MYSQLND_H 24 25 #define MYSQLND_VERSION "mysqlnd 5.0.8-dev - 20102224 - $Id: 731e5b87ba42146a687c29995d2dfd8b4e40b325 $" 26 #define MYSQLND_VERSION_ID 50008 27 28 /* This forces inlining of some accessor functions */ 29 #define MYSQLND_USE_OPTIMISATIONS 0 30 #define AUTOCOMMIT_TX_COMMIT_ROLLBACK 31 32 #define MYSQLND_STRING_TO_INT_CONVERSION 33 /* 34 This force mysqlnd to do a single (or more depending on ammount of data) 35 non-blocking read() calls before sending a command to the server. Useful 36 for debugging, if previous function hasn't consumed all the output sent 37 to it - like stmt_send_long_data() error because the data was larger that 38 max_allowed_packet_size, and COM_STMT_SEND_LONG_DATA by protocol doesn't 39 use response packets, thus letting the next command to fail miserably, if 40 the connector implementor is not aware of this deficiency. Should be off 41 on production systems, if of course measured performance degradation is not 42 minimal. 43 */ 44 #if A0 && PHP_DEBUG 45 #define MYSQLND_DO_WIRE_CHECK_BEFORE_COMMAND 1 46 #endif 47 48 #if PHP_DEBUG 49 #define MYSQLND_DBG_ENABLED 1 50 #else 51 #define MYSQLND_DBG_ENABLED 0 52 #endif 53 54 #if defined(MYSQLND_COMPRESSION_WANTED) && defined(HAVE_ZLIB) 55 #define MYSQLND_COMPRESSION_ENABLED 1 56 #endif 57 58 #ifdef ZTS 59 #include "TSRM.h" 60 #endif 61 62 #include "mysqlnd_portability.h" 63 #include "mysqlnd_enum_n_def.h" 64 #include "mysqlnd_structs.h" 65 66 67 /* Library related */ 68 PHPAPI void mysqlnd_library_init(TSRMLS_D); 69 PHPAPI void mysqlnd_library_end(TSRMLS_D); 70 71 PHPAPI unsigned int mysqlnd_plugin_register(); 72 PHPAPI unsigned int mysqlnd_plugin_count(); 73 PHPAPI void ** _mysqlnd_plugin_get_plugin_connection_data(const MYSQLND * conn, unsigned int plugin_id TSRMLS_DC); 74 #define mysqlnd_plugin_get_plugin_connection_data(c, p_id) _mysqlnd_plugin_get_plugin_connection_data((c), (p_id) TSRMLS_CC) 75 76 PHPAPI void ** _mysqlnd_plugin_get_plugin_result_data(const MYSQLND_RES * result, unsigned int plugin_id TSRMLS_DC); 77 #define mysqlnd_plugin_get_plugin_result_data(r, p_id) _mysqlnd_plugin_get_plugin_result_data((r), (p_id) TSRMLS_CC) 78 79 PHPAPI void ** _mysqlnd_plugin_get_plugin_stmt_data(const MYSQLND_STMT * stmt, unsigned int plugin_id TSRMLS_DC); 80 #define mysqlnd_plugin_get_plugin_stmt_data(s, p_id) _mysqlnd_plugin_get_plugin_stmt_data((s), (p_id) TSRMLS_CC) 81 82 PHPAPI void ** _mysqlnd_plugin_get_plugin_protocol_data(const MYSQLND_PROTOCOL * protocol, unsigned int plugin_id TSRMLS_DC); 83 #define mysqlnd_plugin_get_plugin_protocol_data(p, p_id) _mysqlnd_plugin_get_plugin_protocol_data((p), (p_id) TSRMLS_CC) 84 85 86 PHPAPI struct st_mysqlnd_conn_methods * mysqlnd_conn_get_methods(); 87 PHPAPI void mysqlnd_conn_set_methods(struct st_mysqlnd_conn_methods *methods); 88 89 PHPAPI struct st_mysqlnd_stmt_methods * mysqlnd_stmt_get_methods(); 90 PHPAPI void mysqlnd_stmt_set_methods(struct st_mysqlnd_stmt_methods *methods); 91 92 93 #define mysqlnd_restart_psession(conn) (conn)->m->restart_psession((conn) TSRMLS_CC) 94 #define mysqlnd_end_psession(conn) (conn)->m->end_psession((conn) TSRMLS_CC) 95 PHPAPI void mysqlnd_minfo_print_hash(zval *values); 96 #define mysqlnd_thread_safe() TRUE 97 98 PHPAPI const MYSQLND_CHARSET * mysqlnd_find_charset_nr(unsigned int charsetno); 99 PHPAPI const MYSQLND_CHARSET * mysqlnd_find_charset_name(const char * const charsetname); 100 101 102 /* Connect */ 103 #define mysqlnd_init(persistent) _mysqlnd_init((persistent) TSRMLS_CC) 104 PHPAPI MYSQLND * _mysqlnd_init(zend_bool persistent TSRMLS_DC); 105 PHPAPI MYSQLND * mysqlnd_connect(MYSQLND *conn, 106 const char *host, const char *user, 107 const char *passwd, unsigned int passwd_len, 108 const char *db, unsigned int db_len, 109 unsigned int port, 110 const char *socket_or_pipe, 111 unsigned int mysql_flags 112 TSRMLS_DC); 113 114 #define mysqlnd_change_user(conn, user, passwd, db, silent) (conn)->m->change_user((conn), (user), (passwd), (db), (silent) TSRMLS_CC) 115 116 #define mysqlnd_debug(x) _mysqlnd_debug((x) TSRMLS_CC) 117 PHPAPI void _mysqlnd_debug(const char *mode TSRMLS_DC); 118 119 /* Query */ 120 #define mysqlnd_fetch_into(result, flags, ret_val, ext) (result)->m.fetch_into((result), (flags), (ret_val), (ext) TSRMLS_CC ZEND_FILE_LINE_CC) 121 #define mysqlnd_fetch_row_c(result) (result)->m.fetch_row_c((result) TSRMLS_CC) 122 #define mysqlnd_fetch_all(result, flags, return_value) (result)->m.fetch_all((result), (flags), (return_value) TSRMLS_CC ZEND_FILE_LINE_CC) 123 #define mysqlnd_result_fetch_field_data(res,offset,ret) (res)->m.fetch_field_data((res), (offset), (ret) TSRMLS_CC) 124 #define mysqlnd_get_connection_stats(conn, values) (conn)->m->get_statistics((conn), (values) TSRMLS_CC ZEND_FILE_LINE_CC) 125 #define mysqlnd_get_client_stats(values) _mysqlnd_get_client_stats((values) TSRMLS_CC ZEND_FILE_LINE_CC) 126 127 #define mysqlnd_close(conn,is_forced) (conn)->m->close((conn), (is_forced) TSRMLS_CC) 128 #define mysqlnd_query(conn, query_str, query_len) (conn)->m->query((conn), (query_str), (query_len) TSRMLS_CC) 129 #define mysqlnd_async_query(conn, query_str, query_len) (conn)->m->send_query((conn), (query_str), (query_len) TSRMLS_CC) 130 #define mysqlnd_poll(r, err, d_pull,sec,usec,desc_num) _mysqlnd_poll((r), (err), (d_pull), (sec), (usec), (desc_num) TSRMLS_CC) 131 #define mysqlnd_reap_async_query(conn) (conn)->m->reap_query((conn) TSRMLS_CC) 132 #define mysqlnd_unbuffered_skip_result(result) (result)->m.skip_result((result) TSRMLS_CC) 133 134 PHPAPI enum_func_status _mysqlnd_poll(MYSQLND **r_array, MYSQLND **e_array, MYSQLND ***dont_poll, long sec, long usec, uint * desc_num TSRMLS_DC); 135 136 #define mysqlnd_use_result(conn) (conn)->m->use_result((conn) TSRMLS_CC) 137 #define mysqlnd_store_result(conn) (conn)->m->store_result((conn) TSRMLS_CC) 138 #define mysqlnd_next_result(conn) (conn)->m->next_result((conn) TSRMLS_CC) 139 #define mysqlnd_more_results(conn) (conn)->m->more_results((conn) TSRMLS_CC) 140 #define mysqlnd_free_result(r,e_or_i) ((MYSQLND_RES*)r)->m.free_result(((MYSQLND_RES*)(r)), (e_or_i) TSRMLS_CC) 141 #define mysqlnd_data_seek(result, row) (result)->m.seek_data((result), (row) TSRMLS_CC) 142 143 /* Errors */ 144 #define mysqlnd_errno(conn) (conn)->m->get_error_no((conn) TSRMLS_CC) 145 #define mysqlnd_error(conn) (conn)->m->get_error_str((conn) TSRMLS_CC) 146 #define mysqlnd_sqlstate(conn) (conn)->m->get_sqlstate((conn) TSRMLS_CC) 147 148 /* Charset */ 149 #define mysqlnd_character_set_name(conn) (conn)->m->charset_name((conn) TSRMLS_CC) 150 151 /* Simple metadata */ 152 #define mysqlnd_field_count(conn) (conn)->m->get_field_count((conn) TSRMLS_CC) 153 #define mysqlnd_insert_id(conn) (conn)->m->get_last_insert_id((conn) TSRMLS_CC) 154 #define mysqlnd_affected_rows(conn) (conn)->m->get_affected_rows((conn) TSRMLS_CC) 155 #define mysqlnd_warning_count(conn) (conn)->m->get_warning_count((conn) TSRMLS_CC) 156 #define mysqlnd_info(conn) (conn)->m->get_last_message((conn) TSRMLS_CC) 157 #define mysqlnd_get_server_info(conn) (conn)->m->get_server_information((conn) TSRMLS_CC) 158 #define mysqlnd_get_host_info(conn) (conn)->m->get_host_information((conn) TSRMLS_CC) 159 #define mysqlnd_get_proto_info(conn) (conn)->m->get_protocol_information((conn) TSRMLS_CC) 160 #define mysqlnd_thread_id(conn) (conn)->m->get_thread_id((conn) TSRMLS_CC) 161 162 #define mysqlnd_num_rows(result) (result)->m.num_rows((result) TSRMLS_CC) 163 #define mysqlnd_num_fields(result) (result)->m.num_fields((result) TSRMLS_CC) 164 165 #define mysqlnd_fetch_lengths(result) _mysqlnd_fetch_lengths((result) TSRMLS_CC) 166 PHPAPI unsigned long * _mysqlnd_fetch_lengths(MYSQLND_RES * const result TSRMLS_DC); 167 168 #define mysqlnd_field_seek(result, ofs) (result)->m.seek_field((result), (ofs) TSRMLS_CC) 169 #define mysqlnd_field_tell(result) (result)->m.field_tell((result) TSRMLS_CC) 170 #define mysqlnd_fetch_field(result) (result)->m.fetch_field((result) TSRMLS_CC) 171 #define mysqlnd_fetch_field_direct(result,fnr) (result)->m.fetch_field_direct((result), (fnr) TSRMLS_CC) 172 #define mysqlnd_fetch_fields(result) (result)->m.fetch_fields((result) TSRMLS_CC) 173 174 /* mysqlnd metadata */ 175 PHPAPI const char * mysqlnd_get_client_info(); 176 PHPAPI unsigned int mysqlnd_get_client_version(); 177 178 #define mysqlnd_ssl_set(conn, key, cert, ca, capath, cipher) (conn)->m->ssl_set((conn), (key), (cert), (ca), (capath), (cipher) TSRMLS_CC) 179 180 /* PS */ 181 #define mysqlnd_stmt_insert_id(stmt) (stmt)->m->get_last_insert_id((stmt) TSRMLS_CC) 182 #define mysqlnd_stmt_affected_rows(stmt) (stmt)->m->get_affected_rows((stmt) TSRMLS_CC) 183 #define mysqlnd_stmt_num_rows(stmt) (stmt)->m->get_num_rows((stmt) TSRMLS_CC) 184 #define mysqlnd_stmt_param_count(stmt) (stmt)->m->get_param_count((stmt) TSRMLS_CC) 185 #define mysqlnd_stmt_field_count(stmt) (stmt)->m->get_field_count((stmt) TSRMLS_CC) 186 #define mysqlnd_stmt_warning_count(stmt) (stmt)->m->get_warning_count((stmt) TSRMLS_CC) 187 #define mysqlnd_stmt_server_status(stmt) (stmt)->m->get_server_status((stmt) TSRMLS_CC) 188 #define mysqlnd_stmt_errno(stmt) (stmt)->m->get_error_no((stmt) TSRMLS_CC) 189 #define mysqlnd_stmt_error(stmt) (stmt)->m->get_error_str((stmt) TSRMLS_CC) 190 #define mysqlnd_stmt_sqlstate(stmt) (stmt)->m->get_sqlstate((stmt) TSRMLS_CC) 191 192 193 PHPAPI void mysqlnd_efree_param_bind_dtor(MYSQLND_PARAM_BIND * param_bind TSRMLS_DC); 194 PHPAPI void mysqlnd_efree_result_bind_dtor(MYSQLND_RESULT_BIND * result_bind TSRMLS_DC); 195 PHPAPI void mysqlnd_free_param_bind_dtor(MYSQLND_PARAM_BIND * param_bind TSRMLS_DC); 196 PHPAPI void mysqlnd_free_result_bind_dtor(MYSQLND_RESULT_BIND * result_bind TSRMLS_DC); 197 198 199 PHPAPI const char * mysqlnd_field_type_name(enum mysqlnd_field_types field_type); 200 201 /* LOAD DATA LOCAL */ 202 PHPAPI void mysqlnd_local_infile_default(MYSQLND *conn); 203 PHPAPI void mysqlnd_set_local_infile_handler(MYSQLND * const conn, const char * const funcname); 204 205 /* Simple commands */ 206 #ifdef AUTOCOMMIT_TX_COMMIT_ROLLBACK 207 #define mysqlnd_autocommit(conn, mode) (conn)->m->set_autocommit((conn), (mode) TSRMLS_CC) 208 #define mysqlnd_commit(conn) (conn)->m->tx_commit((conn) TSRMLS_CC) 209 #define mysqlnd_rollback(conn) (conn)->m->tx_rollback((conn) TSRMLS_CC) 210 #else 211 #define mysqlnd_autocommit(conn, mode) (conn)->m->query((conn),(mode) ? "SET AUTOCOMMIT=1":"SET AUTOCOMMIT=0", 16 TSRMLS_CC) 212 #define mysqlnd_commit(conn) (conn)->m->query((conn), "COMMIT", sizeof("COMMIT")-1 TSRMLS_CC) 213 #define mysqlnd_rollback(conn) (conn)->m->query((conn), "ROLLBACK", sizeof("ROLLBACK")-1 TSRMLS_CC) 214 #endif 215 #define mysqlnd_list_dbs(conn, wild) (conn)->m->list_method((conn), wild? "SHOW DATABASES LIKE %s":"SHOW DATABASES", (wild), NULL TSRMLS_CC) 216 #define mysqlnd_list_fields(conn, tab,wild) (conn)->m->list_fields((conn), (tab), (wild) TSRMLS_CC) 217 #define mysqlnd_list_processes(conn) (conn)->m->list_method((conn), "SHOW PROCESSLIST", NULL, NULL TSRMLS_CC) 218 #define mysqlnd_list_tables(conn, wild) (conn)->m->list_method((conn), wild? "SHOW TABLES LIKE %s":"SHOW TABLES", (wild), NULL TSRMLS_CC) 219 #define mysqlnd_dump_debug_info(conn) (conn)->m->server_dump_debug_information((conn) TSRMLS_CC) 220 #define mysqlnd_select_db(conn, db, db_len) (conn)->m->select_db((conn), (db), (db_len) TSRMLS_CC) 221 #define mysqlnd_ping(conn) (conn)->m->ping((conn) TSRMLS_CC) 222 #define mysqlnd_kill(conn, pid) (conn)->m->kill_connection((conn), (pid) TSRMLS_CC) 223 #define mysqlnd_refresh(conn, options) (conn)->m->refresh_server((conn), (options) TSRMLS_CC) 224 #define mysqlnd_shutdown(conn, level) (conn)->m->shutdown_server((conn), (level) TSRMLS_CC) 225 #define mysqlnd_get_server_version(conn) (conn)->m->get_server_version((conn) TSRMLS_CC) 226 #define mysqlnd_set_character_set(conn, cs) (conn)->m->set_charset((conn), (cs) TSRMLS_CC) 227 #define mysqlnd_stat(conn, msg, msg_len) (conn)->m->get_server_statistics((conn), (msg), (msg_len) TSRMLS_CC) 228 #define mysqlnd_options(conn, opt, value) (conn)->m->set_client_option((conn), (opt), (value) TSRMLS_CC) 229 #define mysqlnd_set_server_option(conn, op) (conn)->m->set_server_option((conn), (op) TSRMLS_CC) 230 231 /* Escaping */ 232 #define mysqlnd_real_escape_string(conn, newstr, escapestr, escapestr_len) \ 233 (conn)->m->escape_string((conn), (newstr), (escapestr), (escapestr_len) TSRMLS_CC) 234 #define mysqlnd_escape_string(newstr, escapestr, escapestr_len) \ 235 mysqlnd_old_escape_string((newstr), (escapestr), (escapestr_len) TSRMLS_CC) 236 237 PHPAPI ulong mysqlnd_old_escape_string(char *newstr, const char *escapestr, size_t escapestr_len TSRMLS_DC); 238 239 240 /* PS */ 241 #define mysqlnd_stmt_init(conn) (conn)->m->stmt_init((conn) TSRMLS_CC) 242 #define mysqlnd_stmt_store_result(stmt) (!mysqlnd_stmt_field_count((stmt)) ? PASS:((stmt)->m->store_result((stmt) TSRMLS_CC)? PASS:FAIL)) 243 #define mysqlnd_stmt_get_result(stmt) (stmt)->m->get_result((stmt) TSRMLS_CC) 244 #define mysqlnd_stmt_more_results(stmt) (stmt)->m->more_results((stmt) TSRMLS_CC) 245 #define mysqlnd_stmt_next_result(stmt) (stmt)->m->next_result((stmt) TSRMLS_CC) 246 #define mysqlnd_stmt_data_seek(stmt, row) (stmt)->m->seek_data((stmt), (row) TSRMLS_CC) 247 #define mysqlnd_stmt_prepare(stmt, q, qlen) (stmt)->m->prepare((stmt), (q), (qlen) TSRMLS_CC) 248 #define mysqlnd_stmt_execute(stmt) (stmt)->m->execute((stmt) TSRMLS_CC) 249 #define mysqlnd_stmt_send_long_data(stmt,p,d,l) (stmt)->m->send_long_data((stmt), (p), (d), (l) TSRMLS_CC) 250 #define mysqlnd_stmt_alloc_param_bind(stmt) (stmt)->m->alloc_parameter_bind((stmt) TSRMLS_CC) 251 #define mysqlnd_stmt_free_param_bind(stmt,bind) (stmt)->m->free_parameter_bind((stmt), (bind) TSRMLS_CC) 252 #define mysqlnd_stmt_bind_param(stmt,bind) (stmt)->m->bind_parameters((stmt), (bind) TSRMLS_CC) 253 #define mysqlnd_stmt_bind_one_param(stmt,n,z,t) (stmt)->m->bind_one_parameter((stmt), (n), (z), (t) TSRMLS_CC) 254 #define mysqlnd_stmt_refresh_bind_param(s) (s)->m->refresh_bind_param((s) TSRMLS_CC) 255 #define mysqlnd_stmt_alloc_result_bind(stmt) (stmt)->m->alloc_result_bind((stmt) TSRMLS_CC) 256 #define mysqlnd_stmt_free_result_bind(stmt,bind) (stmt)->m->free_result_bind((stmt), (bind) TSRMLS_CC) 257 #define mysqlnd_stmt_bind_result(stmt,bind) (stmt)->m->bind_result((stmt), (bind) TSRMLS_CC) 258 #define mysqlnd_stmt_bind_one_result(s,no) (s)->m->bind_one_result((s), (no) TSRMLS_CC) 259 #define mysqlnd_stmt_param_metadata(stmt) (stmt)->m->get_parameter_metadata((stmt)) 260 #define mysqlnd_stmt_result_metadata(stmt) (stmt)->m->get_result_metadata((stmt) TSRMLS_CC) 261 262 #define mysqlnd_stmt_free_result(stmt) (stmt)->m->free_result((stmt) TSRMLS_CC) 263 #define mysqlnd_stmt_close(stmt, implicit) (stmt)->m->dtor((stmt), (implicit) TSRMLS_CC) 264 #define mysqlnd_stmt_reset(stmt) (stmt)->m->reset((stmt) TSRMLS_CC) 265 266 267 #define mysqlnd_stmt_attr_get(stmt, attr, value) (stmt)->m->get_attribute((stmt), (attr), (value) TSRMLS_CC) 268 #define mysqlnd_stmt_attr_set(stmt, attr, value) (stmt)->m->set_attribute((stmt), (attr), (value) TSRMLS_CC) 269 270 #define mysqlnd_stmt_fetch(stmt, fetched) (stmt)->m->fetch((stmt), (fetched) TSRMLS_CC) 271 272 273 /* Performance statistics */ 274 PHPAPI void _mysqlnd_get_client_stats(zval *return_value TSRMLS_DC ZEND_FILE_LINE_DC); 275 276 /* double check the class name to avoid naming conflicts when using these: */ 277 #define MYSQLND_METHOD(class, method) php_##class##_##method##_pub 278 #define MYSQLND_METHOD_PRIVATE(class, method) php_##class##_##method##_priv 279 280 ZEND_BEGIN_MODULE_GLOBALS(mysqlnd) 281 zend_bool collect_statistics; 282 zend_bool collect_memory_statistics; 283 char* debug; /* The actual string */ 284 MYSQLND_DEBUG *dbg; /* The DBG object */ 285 long net_cmd_buffer_size; 286 long net_read_buffer_size; 287 long log_mask; 288 long net_read_timeout; 289 long mempool_default_size; 290 long debug_emalloc_fail_threshold; 291 long debug_ecalloc_fail_threshold; 292 long debug_erealloc_fail_threshold; 293 long debug_malloc_fail_threshold; 294 long debug_calloc_fail_threshold; 295 long debug_realloc_fail_threshold; 296 ZEND_END_MODULE_GLOBALS(mysqlnd) 297 298 PHPAPI ZEND_EXTERN_MODULE_GLOBALS(mysqlnd) 299 300 #ifdef ZTS 301 #define MYSQLND_G(v) TSRMG(mysqlnd_globals_id, zend_mysqlnd_globals *, v) 302 #else 303 #define MYSQLND_G(v) (mysqlnd_globals.v) 304 #endif 305 306 307 PHPAPI void mysqlnd_minfo_print_hash(zval *values); 308 309 #endif /* MYSQLND_H */ 310 311 312 /* 313 * Local variables: 314 * tab-width: 4 315 * c-basic-offset: 4 316 * End: 317 * vim600: noet sw=4 ts=4 fdm=marker 318 * vim<600: noet sw=4 ts=4 319 */ 320