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