1 /*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Author: George Schlossnagle <george@omniti.com> |
14 | Wez Furlong <wez@php.net> |
15 | Johannes Schlueter <johannes@mysql.com> |
16 +----------------------------------------------------------------------+
17 */
18
19 #ifndef PHP_PDO_MYSQL_INT_H
20 #define PHP_PDO_MYSQL_INT_H
21
22 #ifdef PDO_USE_MYSQLND
23 # include "ext/mysqlnd/mysqlnd.h"
24 # include "ext/mysqlnd/mysqlnd_libmysql_compat.h"
25 # define PDO_MYSQL_PARAM_BIND MYSQLND_PARAM_BIND
26 #else
27 # include <mysql.h>
28 #if MYSQL_VERSION_ID >= 80000 && MYSQL_VERSION_ID < 100000
29 typedef _Bool my_bool;
30 #endif
31 # define PDO_MYSQL_PARAM_BIND MYSQL_BIND
32 #endif
33
34 #if defined(PDO_USE_MYSQLND) && PHP_DEBUG && !defined(PHP_WIN32)
35 #define PDO_DBG_ENABLED 1
36
37 #define PDO_DBG_INF(msg) do { if (!dbg_skip_trace) PDO_MYSQL_G(dbg)->m->log(PDO_MYSQL_G(dbg), __LINE__, __FILE__, -1, "info : ", (msg)); } while (0)
38 #define PDO_DBG_ERR(msg) do { if (!dbg_skip_trace) PDO_MYSQL_G(dbg)->m->log(PDO_MYSQL_G(dbg), __LINE__, __FILE__, -1, "error: ", (msg)); } while (0)
39 #define PDO_DBG_INF_FMT(...) do { if (!dbg_skip_trace) PDO_MYSQL_G(dbg)->m->log_va(PDO_MYSQL_G(dbg), __LINE__, __FILE__, -1, "info : ", __VA_ARGS__); } while (0)
40 #define PDO_DBG_ERR_FMT(...) do { if (!dbg_skip_trace) PDO_MYSQL_G(dbg)->m->log_va(PDO_MYSQL_G(dbg), __LINE__, __FILE__, -1, "error: ", __VA_ARGS__); } while (0)
41 #define PDO_DBG_ENTER(func_name) \
42 bool dbg_skip_trace = true; \
43 ((void) dbg_skip_trace); \
44 if (PDO_MYSQL_G(dbg)) \
45 dbg_skip_trace = !PDO_MYSQL_G(dbg)->m->func_enter(PDO_MYSQL_G(dbg), __LINE__, __FILE__, func_name, strlen(func_name));
46
47 #define PDO_DBG_RETURN(value) do { if (PDO_MYSQL_G(dbg)) PDO_MYSQL_G(dbg)->m->func_leave(PDO_MYSQL_G(dbg), __LINE__, __FILE__, 0); return (value); } while (0)
48 #define PDO_DBG_VOID_RETURN do { if (PDO_MYSQL_G(dbg)) PDO_MYSQL_G(dbg)->m->func_leave(PDO_MYSQL_G(dbg), __LINE__, __FILE__, 0); return; } while (0)
49
50 #else
51 #define PDO_DBG_ENABLED 0
52
PDO_DBG_INF(char * msg)53 static inline void PDO_DBG_INF(char *msg) {}
PDO_DBG_ERR(char * msg)54 static inline void PDO_DBG_ERR(char *msg) {}
PDO_DBG_INF_FMT(char * format,...)55 static inline void PDO_DBG_INF_FMT(char *format, ...) {}
PDO_DBG_ERR_FMT(char * format,...)56 static inline void PDO_DBG_ERR_FMT(char *format, ...) {}
PDO_DBG_ENTER(char * func_name)57 static inline void PDO_DBG_ENTER(char *func_name) {}
58 #define PDO_DBG_RETURN(value) return (value)
59 #define PDO_DBG_VOID_RETURN return;
60
61 #endif
62
63 #ifdef PDO_USE_MYSQLND
64 #include "ext/mysqlnd/mysqlnd_debug.h"
65 #endif
66
67 ZEND_BEGIN_MODULE_GLOBALS(pdo_mysql)
68 #ifndef PHP_WIN32
69 char *default_socket;
70 #endif
71 #if PDO_DBG_ENABLED
72 char *debug; /* The actual string */
73 MYSQLND_DEBUG *dbg; /* The DBG object */
74 #endif
75 #if defined(PHP_WIN32) && !PDO_DBG_ENABLED
76 /* dummy member so we get at least one member in the struct
77 * and avoids build errors.
78 */
79 void *dummymemmber;
80 #endif
81 ZEND_END_MODULE_GLOBALS(pdo_mysql)
82
83 ZEND_EXTERN_MODULE_GLOBALS(pdo_mysql)
84 #define PDO_MYSQL_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(pdo_mysql, v)
85
86 #if defined(ZTS) && defined(COMPILE_DL_PDO_MYSQL)
87 ZEND_TSRMLS_CACHE_EXTERN()
88 #endif
89
90
91 typedef struct {
92 const char *file;
93 int line;
94 unsigned int errcode;
95 char *errmsg;
96 } pdo_mysql_error_info;
97
98 /* stuff we use in a mySQL database handle */
99 typedef struct {
100 MYSQL *server;
101
102 unsigned assume_national_character_set_strings:1;
103 unsigned attached:1;
104 unsigned buffered:1;
105 unsigned emulate_prepare:1;
106 unsigned fetch_table_names:1;
107 unsigned local_infile:1;
108 #ifndef PDO_USE_MYSQLND
109 zend_ulong max_buffer_size;
110 #endif
111
112 pdo_mysql_error_info einfo;
113 } pdo_mysql_db_handle;
114
115 typedef struct {
116 MYSQL_FIELD *def;
117 } pdo_mysql_column;
118
119 typedef struct {
120 pdo_mysql_db_handle *H;
121 MYSQL_RES *result;
122 const MYSQL_FIELD *fields;
123 pdo_mysql_error_info einfo;
124 #ifdef PDO_USE_MYSQLND
125 MYSQLND_STMT *stmt;
126 #else
127 MYSQL_STMT *stmt;
128 #endif
129 int num_params;
130 PDO_MYSQL_PARAM_BIND *params;
131 #ifndef PDO_USE_MYSQLND
132 my_bool *in_null;
133 zend_ulong *in_length;
134 PDO_MYSQL_PARAM_BIND *bound_result;
135 my_bool *out_null;
136 zend_ulong *out_length;
137 MYSQL_ROW current_data;
138 unsigned long *current_lengths;
139 #else
140 zval *current_row;
141 #endif
142 unsigned max_length:1;
143 /* Whether all result sets have been fully consumed.
144 * If this flag is not set, they need to be consumed during destruction. */
145 unsigned done:1;
146 } pdo_mysql_stmt;
147
148 extern const pdo_driver_t pdo_mysql_driver;
149
150 extern int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line);
151 #define pdo_mysql_error(s) _pdo_mysql_error(s, NULL, __FILE__, __LINE__)
152 #define pdo_mysql_error_stmt(s) _pdo_mysql_error(stmt->dbh, stmt, __FILE__, __LINE__)
153
154 extern const struct pdo_stmt_methods mysql_stmt_methods;
155
156 enum {
157 PDO_MYSQL_ATTR_USE_BUFFERED_QUERY = PDO_ATTR_DRIVER_SPECIFIC,
158 PDO_MYSQL_ATTR_LOCAL_INFILE,
159 PDO_MYSQL_ATTR_INIT_COMMAND,
160 #ifndef PDO_USE_MYSQLND
161 PDO_MYSQL_ATTR_READ_DEFAULT_FILE,
162 PDO_MYSQL_ATTR_READ_DEFAULT_GROUP,
163 PDO_MYSQL_ATTR_MAX_BUFFER_SIZE,
164 #endif
165 PDO_MYSQL_ATTR_COMPRESS,
166 PDO_MYSQL_ATTR_DIRECT_QUERY,
167 PDO_MYSQL_ATTR_FOUND_ROWS,
168 PDO_MYSQL_ATTR_IGNORE_SPACE,
169 PDO_MYSQL_ATTR_SSL_KEY,
170 PDO_MYSQL_ATTR_SSL_CERT,
171 PDO_MYSQL_ATTR_SSL_CA,
172 PDO_MYSQL_ATTR_SSL_CAPATH,
173 PDO_MYSQL_ATTR_SSL_CIPHER,
174 #if MYSQL_VERSION_ID > 50605 || defined(PDO_USE_MYSQLND)
175 PDO_MYSQL_ATTR_SERVER_PUBLIC_KEY,
176 #endif
177 PDO_MYSQL_ATTR_MULTI_STATEMENTS,
178 #ifdef PDO_USE_MYSQLND
179 PDO_MYSQL_ATTR_SSL_VERIFY_SERVER_CERT,
180 #endif
181 #if MYSQL_VERSION_ID >= 80021 || defined(PDO_USE_MYSQLND)
182 PDO_MYSQL_ATTR_LOCAL_INFILE_DIRECTORY,
183 #endif
184 };
185
186 #endif
187