xref: /php-src/ext/mysqli/mysqli_priv.h (revision d84dfa32)
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 extern MYSQLI_WARNING *php_get_warnings(MYSQLND_CONN_DATA * mysql);
56 
57 extern void php_clear_warnings(MYSQLI_WARNING *w);
58 extern void php_free_stmt_bind_buffer(BIND_BUFFER bbuf, int type);
59 extern void php_mysqli_report_error(const char *sqlstate, int errorno, const char *error);
60 extern void php_mysqli_report_index(const char *query, unsigned int status);
61 extern void php_mysqli_throw_sql_exception(char *sqlstate, int errorno, char *format, ...);
62 
63 #define PHP_MYSQLI_EXPORT(__type) PHP_MYSQLI_API __type
64 
65 PHP_MYSQLI_EXPORT(zend_object *) mysqli_objects_new(zend_class_entry *);
66 
67 #define MYSQLI_DISABLE_MQ if (mysql->multi_query) { \
68 	mysql_set_server_option(mysql->mysql, MYSQL_OPTION_MULTI_STATEMENTS_OFF); \
69 	mysql->multi_query = 0; \
70 }
71 
72 #define MYSQLI_ENABLE_MQ if (!mysql->multi_query) { \
73 	mysql_set_server_option(mysql->mysql, MYSQL_OPTION_MULTI_STATEMENTS_ON); \
74 	mysql->multi_query = 1; \
75 }
76 
77 /* Numbers that cannot be represented as a signed int are converted to a string instead (affects 32-bit builds). */
78 #define MYSQLI_RETURN_LONG_INT(__val) \
79 { \
80 	if ((__val) < ZEND_LONG_MAX) {		\
81 		RETURN_LONG((zend_long) (__val));		\
82 	} else {				\
83 		/* always used with my_ulonglong -> %llu */ \
84 		RETURN_STR(strpprintf(0, MYSQLI_LLU_SPEC, (__val)));	\
85 	} \
86 }
87 
88 #define MYSQLI_STORE_RESULT 0
89 #define MYSQLI_USE_RESULT 	1
90 #define MYSQLI_ASYNC	 	8
91 #define MYSQLI_STORE_RESULT_COPY_DATA 16
92 
93 /* for mysqli_fetch_assoc */
94 #define MYSQLI_ASSOC	1
95 #define MYSQLI_NUM		2
96 #define MYSQLI_BOTH		3
97 
98 /* fetch types */
99 #define FETCH_SIMPLE		1
100 #define FETCH_RESULT		2
101 
102 /*** REPORT MODES ***/
103 #define MYSQLI_REPORT_OFF           0
104 #define MYSQLI_REPORT_ERROR			1
105 #define MYSQLI_REPORT_STRICT		2
106 #define MYSQLI_REPORT_INDEX			4
107 #define MYSQLI_REPORT_CLOSE			8
108 #define MYSQLI_REPORT_ALL		  255
109 
110 #define MYSQLI_REPORT_MYSQL_ERROR(mysql) \
111 if ((MyG(report_mode) & MYSQLI_REPORT_ERROR) && mysql_errno(mysql)) { \
112 	php_mysqli_report_error(mysql_sqlstate(mysql), mysql_errno(mysql), mysql_error(mysql)); \
113 }
114 
115 #define MYSQLI_REPORT_STMT_ERROR(stmt) \
116 if ((MyG(report_mode) & MYSQLI_REPORT_ERROR) && mysql_stmt_errno(stmt)) { \
117 	php_mysqli_report_error(mysql_stmt_sqlstate(stmt), mysql_stmt_errno(stmt), mysql_stmt_error(stmt)); \
118 }
119 
120 void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, bool is_real_connect, bool in_ctor);
121 
122 void php_mysqli_init(INTERNAL_FUNCTION_PARAMETERS, bool is_method);
123 
124 #endif /* MYSQLI_PRIV_H */
125