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 | http://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 == FALSE) 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 == FALSE) 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 == FALSE) 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 == FALSE) 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 zend_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 MYSQL_ROW current_data;
124 #ifdef PDO_USE_MYSQLND
125 const size_t *current_lengths;
126 #else
127 unsigned long *current_lengths;
128 #endif
129 pdo_mysql_error_info einfo;
130 #ifdef PDO_USE_MYSQLND
131 MYSQLND_STMT *stmt;
132 #else
133 MYSQL_STMT *stmt;
134 #endif
135 int num_params;
136 PDO_MYSQL_PARAM_BIND *params;
137 #ifndef PDO_USE_MYSQLND
138 my_bool *in_null;
139 zend_ulong *in_length;
140 #endif
141 PDO_MYSQL_PARAM_BIND *bound_result;
142 my_bool *out_null;
143 zend_ulong *out_length;
144 unsigned max_length:1;
145 /* Whether all result sets have been fully consumed.
146 * If this flag is not set, they need to be consumed during destruction. */
147 unsigned done:1;
148 } pdo_mysql_stmt;
149
150 extern const pdo_driver_t pdo_mysql_driver;
151
152 extern int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line);
153 #define pdo_mysql_error(s) _pdo_mysql_error(s, NULL, __FILE__, __LINE__)
154 #define pdo_mysql_error_stmt(s) _pdo_mysql_error(stmt->dbh, stmt, __FILE__, __LINE__)
155
156 extern const struct pdo_stmt_methods mysql_stmt_methods;
157
158 enum {
159 PDO_MYSQL_ATTR_USE_BUFFERED_QUERY = PDO_ATTR_DRIVER_SPECIFIC,
160 PDO_MYSQL_ATTR_LOCAL_INFILE,
161 PDO_MYSQL_ATTR_INIT_COMMAND,
162 #ifndef PDO_USE_MYSQLND
163 PDO_MYSQL_ATTR_READ_DEFAULT_FILE,
164 PDO_MYSQL_ATTR_READ_DEFAULT_GROUP,
165 PDO_MYSQL_ATTR_MAX_BUFFER_SIZE,
166 #endif
167 PDO_MYSQL_ATTR_COMPRESS,
168 PDO_MYSQL_ATTR_DIRECT_QUERY,
169 PDO_MYSQL_ATTR_FOUND_ROWS,
170 PDO_MYSQL_ATTR_IGNORE_SPACE,
171 PDO_MYSQL_ATTR_SSL_KEY,
172 PDO_MYSQL_ATTR_SSL_CERT,
173 PDO_MYSQL_ATTR_SSL_CA,
174 PDO_MYSQL_ATTR_SSL_CAPATH,
175 PDO_MYSQL_ATTR_SSL_CIPHER,
176 #if MYSQL_VERSION_ID > 50605 || defined(PDO_USE_MYSQLND)
177 PDO_MYSQL_ATTR_SERVER_PUBLIC_KEY,
178 #endif
179 PDO_MYSQL_ATTR_MULTI_STATEMENTS,
180 #ifdef PDO_USE_MYSQLND
181 PDO_MYSQL_ATTR_SSL_VERIFY_SERVER_CERT,
182 #endif
183 };
184
185 #endif
186