xref: /PHP-7.3/ext/mysqli/mysqli_priv.h (revision 5d3e3a62)
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: Georg Richter <georg@php.net>                                |
16   +----------------------------------------------------------------------+
17 */
18 
19 #ifndef MYSQLI_PRIV_H
20 #define MYSQLI_PRIV_H
21 
22 #ifdef PHP_MYSQL_UNIX_SOCK_ADDR
23 #ifdef MYSQL_UNIX_ADDR
24 #undef MYSQL_UNIX_ADDR
25 #endif
26 #define MYSQL_UNIX_ADDR PHP_MYSQL_UNIX_SOCK_ADDR
27 #endif
28 
29 /* character set support */
30 #if defined(MYSQLND_VERSION_ID) || MYSQL_VERSION_ID > 50009
31 #define HAVE_MYSQLI_GET_CHARSET
32 #endif
33 
34 #if defined(MYSQLND_VERSION_ID) || MYSQL_VERSION_ID > 50005
35 #define HAVE_MYSQLI_SET_CHARSET
36 #endif
37 
38 
39 extern const zend_function_entry mysqli_functions[];
40 extern const zend_function_entry mysqli_link_methods[];
41 extern const zend_function_entry mysqli_stmt_methods[];
42 extern const zend_function_entry mysqli_result_methods[];
43 extern const zend_function_entry mysqli_driver_methods[];
44 extern const zend_function_entry mysqli_warning_methods[];
45 extern const zend_function_entry mysqli_exception_methods[];
46 
47 extern const mysqli_property_entry mysqli_link_property_entries[];
48 extern const mysqli_property_entry mysqli_result_property_entries[];
49 extern const mysqli_property_entry mysqli_stmt_property_entries[];
50 extern const mysqli_property_entry mysqli_driver_property_entries[];
51 extern const mysqli_property_entry mysqli_warning_property_entries[];
52 
53 extern const zend_property_info mysqli_link_property_info_entries[];
54 extern const zend_property_info mysqli_result_property_info_entries[];
55 extern const zend_property_info mysqli_stmt_property_info_entries[];
56 extern const zend_property_info mysqli_driver_property_info_entries[];
57 extern const zend_property_info mysqli_warning_property_info_entries[];
58 
59 extern int php_le_pmysqli(void);
60 extern void php_mysqli_dtor_p_elements(void *data);
61 
62 extern void php_mysqli_close(MY_MYSQL * mysql, int close_type, int resource_status);
63 
64 extern void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flag, int into_object);
65 extern void php_clear_stmt_bind(MY_STMT *stmt);
66 extern void php_clear_mysql(MY_MYSQL *);
67 #ifdef MYSQLI_USE_MYSQLND
68 extern MYSQLI_WARNING *php_get_warnings(MYSQLND_CONN_DATA * mysql);
69 #else
70 extern MYSQLI_WARNING *php_get_warnings(MYSQL * mysql);
71 #endif
72 
73 extern void php_clear_warnings(MYSQLI_WARNING *w);
74 extern void php_free_stmt_bind_buffer(BIND_BUFFER bbuf, int type);
75 extern void php_mysqli_report_error(const char *sqlstate, int errorno, const char *error);
76 extern void php_mysqli_report_index(const char *query, unsigned int status);
77 extern void php_mysqli_throw_sql_exception(char *sqlstate, int errorno, char *format, ...);
78 
79 #define PHP_MYSQLI_EXPORT(__type) PHP_MYSQLI_API __type
80 
81 PHP_MYSQLI_EXPORT(zend_object *) mysqli_objects_new(zend_class_entry *);
82 
83 #define MYSQLI_DISABLE_MQ if (mysql->multi_query) { \
84 	mysql_set_server_option(mysql->mysql, MYSQL_OPTION_MULTI_STATEMENTS_OFF); \
85 	mysql->multi_query = 0; \
86 }
87 
88 #define MYSQLI_ENABLE_MQ if (!mysql->multi_query) { \
89 	mysql_set_server_option(mysql->mysql, MYSQL_OPTION_MULTI_STATEMENTS_ON); \
90 	mysql->multi_query = 1; \
91 }
92 
93 /* Numbers that cannot be represented as a signed int are converted to a string instead (affects 32-bit builds). */
94 #define MYSQLI_RETURN_LONG_INT(__val) \
95 { \
96 	if ((__val) < ZEND_LONG_MAX) {		\
97 		RETURN_LONG((zend_long) (__val));		\
98 	} else {				\
99 		/* always used with my_ulonglong -> %llu */ \
100 		RETURN_STR(strpprintf(0, MYSQLI_LLU_SPEC, (__val)));	\
101 	} \
102 }
103 
104 #define MYSQLI_STORE_RESULT 0
105 #define MYSQLI_USE_RESULT 	1
106 #ifdef MYSQLI_USE_MYSQLND
107 #define MYSQLI_ASYNC	 	8
108 #define MYSQLI_STORE_RESULT_COPY_DATA 16
109 #else
110 /* libmysql */
111 #define MYSQLI_ASYNC	 	0
112 #define MYSQLI_STORE_RESULT_COPY_DATA	0
113 #endif
114 
115 /* for mysqli_fetch_assoc */
116 #define MYSQLI_ASSOC	1
117 #define MYSQLI_NUM		2
118 #define MYSQLI_BOTH		3
119 
120 /* fetch types */
121 #define FETCH_SIMPLE		1
122 #define FETCH_RESULT		2
123 
124 /*** REPORT MODES ***/
125 #define MYSQLI_REPORT_OFF           0
126 #define MYSQLI_REPORT_ERROR			1
127 #define MYSQLI_REPORT_STRICT		2
128 #define MYSQLI_REPORT_INDEX			4
129 #define MYSQLI_REPORT_CLOSE			8
130 #define MYSQLI_REPORT_ALL		  255
131 
132 #define MYSQLI_REPORT_MYSQL_ERROR(mysql) \
133 if ((MyG(report_mode) & MYSQLI_REPORT_ERROR) && mysql_errno(mysql)) { \
134 	php_mysqli_report_error(mysql_sqlstate(mysql), mysql_errno(mysql), mysql_error(mysql)); \
135 }
136 
137 #define MYSQLI_REPORT_STMT_ERROR(stmt) \
138 if ((MyG(report_mode) & MYSQLI_REPORT_ERROR) && mysql_stmt_errno(stmt)) { \
139 	php_mysqli_report_error(mysql_stmt_sqlstate(stmt), mysql_stmt_errno(stmt), mysql_stmt_error(stmt)); \
140 }
141 
142 void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_connect, zend_bool in_ctor);
143 
144 void php_mysqli_init(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_method);
145 
146 #endif /* MYSQLI_PRIV_H */
147