xref: /PHP-7.2/ext/pdo_mysql/php_pdo_mysql_int.h (revision 7a7ec01a)
1 /*
2   +----------------------------------------------------------------------+
3   | PHP Version 7                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 1997-2018 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   | Author: George Schlossnagle <george@omniti.com>                      |
16   |         Wez Furlong <wez@php.net>                                    |
17   |         Johannes Schlueter <johannes@mysql.com>                      |
18   +----------------------------------------------------------------------+
19 */
20 
21 /* $Id$ */
22 
23 #ifndef PHP_PDO_MYSQL_INT_H
24 #define PHP_PDO_MYSQL_INT_H
25 
26 #if defined(PDO_USE_MYSQLND)
27 #	include "ext/mysqlnd/mysqlnd.h"
28 #	include "ext/mysqlnd/mysqlnd_libmysql_compat.h"
29 #	define PDO_MYSQL_PARAM_BIND MYSQLND_PARAM_BIND
30 #else
31 #	include <mysql.h>
32 #	define PDO_MYSQL_PARAM_BIND MYSQL_BIND
33 #endif
34 
35 #if (MYSQL_VERSION_ID >= 40113 && MYSQL_VERSION_ID < 50000) || MYSQL_VERSION_ID >= 50007 || defined(MYSQL_USE_MYSQLND)
36 # define PDO_MYSQL_HAS_CHARSET
37 #endif
38 
39 #if defined(PDO_USE_MYSQLND) && PHP_DEBUG && !defined(PHP_WIN32)
40 #define PDO_DBG_ENABLED 1
41 
42 #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)
43 #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)
44 #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)
45 #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)
46 #define PDO_DBG_ENTER(func_name) \
47 	zend_bool dbg_skip_trace = TRUE; \
48 	((void) dbg_skip_trace); \
49 	if (PDO_MYSQL_G(dbg)) \
50 		dbg_skip_trace = !PDO_MYSQL_G(dbg)->m->func_enter(PDO_MYSQL_G(dbg), __LINE__, __FILE__, func_name, strlen(func_name));
51 
52 #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)
53 #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)
54 
55 #else
56 #define PDO_DBG_ENABLED 0
57 
PDO_DBG_INF(char * msg)58 static inline void PDO_DBG_INF(char *msg) {}
PDO_DBG_ERR(char * msg)59 static inline void PDO_DBG_ERR(char *msg) {}
PDO_DBG_INF_FMT(char * format,...)60 static inline void PDO_DBG_INF_FMT(char *format, ...) {}
PDO_DBG_ERR_FMT(char * format,...)61 static inline void PDO_DBG_ERR_FMT(char *format, ...) {}
PDO_DBG_ENTER(char * func_name)62 static inline void PDO_DBG_ENTER(char *func_name) {}
63 #define PDO_DBG_RETURN(value)	return (value)
64 #define PDO_DBG_VOID_RETURN		return;
65 
66 #endif
67 
68 #if defined(PDO_USE_MYSQLND)
69 #include "ext/mysqlnd/mysqlnd_debug.h"
70 #endif
71 
72 ZEND_BEGIN_MODULE_GLOBALS(pdo_mysql)
73 #ifndef PHP_WIN32
74 	char          *default_socket;
75 #endif
76 #if PDO_DBG_ENABLED
77 	char          *debug; /* The actual string */
78 	MYSQLND_DEBUG *dbg;	/* The DBG object */
79 #endif
80 #if defined(PHP_WIN32) && !PDO_DBG_ENABLED
81 	/* dummy member so we get at least one member in the struct
82 	 * and avoids build errors.
83 	 */
84 	void *dummymemmber;
85 #endif
86 ZEND_END_MODULE_GLOBALS(pdo_mysql)
87 
88 ZEND_EXTERN_MODULE_GLOBALS(pdo_mysql)
89 #define PDO_MYSQL_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(pdo_mysql, v)
90 
91 #if defined(ZTS) && defined(COMPILE_DL_PDO_MYSQL)
92 ZEND_TSRMLS_CACHE_EXTERN()
93 #endif
94 
95 
96 typedef struct {
97 	const char *file;
98 	int line;
99 	unsigned int errcode;
100 	char *errmsg;
101 } pdo_mysql_error_info;
102 
103 /* stuff we use in a mySQL database handle */
104 typedef struct {
105 	MYSQL 		*server;
106 
107 	unsigned assume_national_character_set_strings:1;
108 	unsigned attached:1;
109 	unsigned buffered:1;
110 	unsigned emulate_prepare:1;
111 	unsigned fetch_table_names:1;
112 #if !PDO_USE_MYSQLND
113 	zend_ulong max_buffer_size;
114 #endif
115 
116 	pdo_mysql_error_info einfo;
117 } pdo_mysql_db_handle;
118 
119 typedef struct {
120 	MYSQL_FIELD		*def;
121 } pdo_mysql_column;
122 
123 typedef struct {
124 	pdo_mysql_db_handle 	*H;
125 	MYSQL_RES				*result;
126 	const MYSQL_FIELD		*fields;
127 	MYSQL_ROW				current_data;
128 #if PDO_USE_MYSQLND
129 	const size_t			*current_lengths;
130 #else
131 	zend_long				*current_lengths;
132 #endif
133 	pdo_mysql_error_info 	einfo;
134 #if PDO_USE_MYSQLND
135 	MYSQLND_STMT 			*stmt;
136 #else
137 	MYSQL_STMT				*stmt;
138 #endif
139 	int 					num_params;
140 	PDO_MYSQL_PARAM_BIND	*params;
141 #ifndef PDO_USE_MYSQLND
142 	my_bool					*in_null;
143 	zend_ulong			*in_length;
144 #endif
145 	PDO_MYSQL_PARAM_BIND	*bound_result;
146 	my_bool					*out_null;
147 	zend_ulong				*out_length;
148 	unsigned int			params_given;
149 	unsigned				max_length:1;
150 } pdo_mysql_stmt;
151 
152 extern pdo_driver_t pdo_mysql_driver;
153 
154 extern int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line);
155 #define pdo_mysql_error(s) _pdo_mysql_error(s, NULL, __FILE__, __LINE__)
156 #define pdo_mysql_error_stmt(s) _pdo_mysql_error(stmt->dbh, stmt, __FILE__, __LINE__)
157 
158 extern struct pdo_stmt_methods mysql_stmt_methods;
159 
160 enum {
161 	PDO_MYSQL_ATTR_USE_BUFFERED_QUERY = PDO_ATTR_DRIVER_SPECIFIC,
162 	PDO_MYSQL_ATTR_LOCAL_INFILE,
163 	PDO_MYSQL_ATTR_INIT_COMMAND,
164 #ifndef PDO_USE_MYSQLND
165 	PDO_MYSQL_ATTR_READ_DEFAULT_FILE,
166 	PDO_MYSQL_ATTR_READ_DEFAULT_GROUP,
167 	PDO_MYSQL_ATTR_MAX_BUFFER_SIZE,
168 #endif
169 	PDO_MYSQL_ATTR_COMPRESS,
170 	PDO_MYSQL_ATTR_DIRECT_QUERY,
171 	PDO_MYSQL_ATTR_FOUND_ROWS,
172 	PDO_MYSQL_ATTR_IGNORE_SPACE,
173 	PDO_MYSQL_ATTR_SSL_KEY,
174 	PDO_MYSQL_ATTR_SSL_CERT,
175 	PDO_MYSQL_ATTR_SSL_CA,
176 	PDO_MYSQL_ATTR_SSL_CAPATH,
177 	PDO_MYSQL_ATTR_SSL_CIPHER,
178 #if MYSQL_VERSION_ID > 50605 || defined(PDO_USE_MYSQLND)
179 	PDO_MYSQL_ATTR_SERVER_PUBLIC_KEY,
180 #endif
181 	PDO_MYSQL_ATTR_MULTI_STATEMENTS,
182 #ifdef PDO_USE_MYSQLND
183 	PDO_MYSQL_ATTR_SSL_VERIFY_SERVER_CERT,
184 #endif
185 };
186 
187 #endif
188