xref: /PHP-7.1/ext/mysqli/mysqli_driver.c (revision ccd4716e)
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 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22 
23 #include <signal.h>
24 
25 #include "php.h"
26 #include "php_ini.h"
27 #include "ext/standard/info.h"
28 #include "php_mysqli_structs.h"
29 #include "zend_exceptions.h"
30 #include "mysqli_fe.h"
31 
32 #define MAP_PROPERTY_MYG_BOOL_READ(name, value) \
33 static zval *name(mysqli_object *obj, zval *retval) \
34 { \
35 	ZVAL_BOOL(retval, MyG(value)); \
36 	return retval; \
37 } \
38 
39 #define MAP_PROPERTY_MYG_BOOL_WRITE(name, value) \
40 static int name(mysqli_object *obj, zval *value) \
41 { \
42 	MyG(value) = Z_LVAL_P(value) > 0; \
43 	return SUCCESS; \
44 } \
45 
46 #define MAP_PROPERTY_MYG_LONG_READ(name, value) \
47 static zval *name(mysqli_object *obj, zval *retval) \
48 { \
49 	ZVAL_LONG(retval, MyG(value)); \
50 	return retval; \
51 } \
52 
53 #define MAP_PROPERTY_MYG_LONG_WRITE(name, value) \
54 static int name(mysqli_object *obj, zval *value) \
55 { \
56 	MyG(value) = Z_LVAL_P(value); \
57 	return SUCCESS; \
58 } \
59 
60 #define MAP_PROPERTY_MYG_STRING_READ(name, value) \
61 static zval *name(mysqli_object *obj, zval *retval) \
62 { \
63 	ZVAL_STRING(retval, MyG(value)); \
64 	return retval; \
65 } \
66 
67 #define MAP_PROPERTY_MYG_STRING_WRITE(name, value) \
68 static int name(mysqli_object *obj, zval *value) \
69 { \
70 	MyG(value) = Z_STRVAL_P(value); \
71 	return SUCCESS; \
72 } \
73 
74 /* {{{ property driver_report_write */
driver_report_write(mysqli_object * obj,zval * value)75 static int driver_report_write(mysqli_object *obj, zval *value)
76 {
77 	MyG(report_mode) = Z_LVAL_P(value);
78 	/*FIXME*/
79 	/* zend_replace_error_handling(MyG(report_mode) & MYSQLI_REPORT_STRICT ? EH_THROW : EH_NORMAL, NULL, NULL); */
80 	return SUCCESS;
81 }
82 /* }}} */
83 
84 /* {{{ property driver_embedded_read */
driver_embedded_read(mysqli_object * obj,zval * retval)85 static zval *driver_embedded_read(mysqli_object *obj, zval *retval)
86 {
87 #ifdef HAVE_EMBEDDED_MYSQLI
88 	ZVAL_TRUE(retval);
89 #else
90 	ZVAL_FALSE(retval);
91 #endif
92 	return retval;
93 }
94 /* }}} */
95 
96 /* {{{ property driver_client_version_read */
driver_client_version_read(mysqli_object * obj,zval * retval)97 static zval *driver_client_version_read(mysqli_object *obj, zval *retval)
98 {
99 	ZVAL_LONG(retval, MYSQL_VERSION_ID);
100 	return retval;
101 }
102 /* }}} */
103 
104 /* {{{ property driver_client_info_read */
driver_client_info_read(mysqli_object * obj,zval * retval)105 static zval *driver_client_info_read(mysqli_object *obj, zval *retval)
106 {
107 	ZVAL_STRING(retval, (char *)mysql_get_client_info());
108 	return retval;
109 }
110 /* }}} */
111 
112 /* {{{ property driver_driver_version_read */
driver_driver_version_read(mysqli_object * obj,zval * retval)113 static zval *driver_driver_version_read(mysqli_object *obj, zval *retval)
114 {
115 	ZVAL_LONG(retval, MYSQLI_VERSION_ID);
116 	return retval;
117 }
118 /* }}} */
119 
MAP_PROPERTY_MYG_BOOL_READ(driver_reconnect_read,reconnect)120 MAP_PROPERTY_MYG_BOOL_READ(driver_reconnect_read, reconnect)
121 MAP_PROPERTY_MYG_BOOL_WRITE(driver_reconnect_write, reconnect)
122 MAP_PROPERTY_MYG_LONG_READ(driver_report_read, report_mode)
123 
124 ZEND_FUNCTION(mysqli_driver_construct)
125 {
126 #if G0
127 	MYSQLI_RESOURCE 	*mysqli_resource;
128 
129 	mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
130 	mysqli_resource->ptr = 1;
131 	mysqli_resource->status = (ZEND_NUM_ARGS() == 1) ? MYSQLI_STATUS_INITIALIZED : MYSQLI_STATUS_VALID;
132 	(Z_MYSQLI_P(getThis()))->ptr = mysqli_resource;
133 #endif
134 }
135 
136 const mysqli_property_entry mysqli_driver_property_entries[] = {
137 	{"client_info", sizeof("client_info") - 1, driver_client_info_read, NULL},
138 	{"client_version", sizeof("client_version") - 1, driver_client_version_read, NULL},
139 	{"driver_version", sizeof("driver_version") - 1, driver_driver_version_read, NULL},
140 	{"embedded", sizeof("embedded") - 1, driver_embedded_read, NULL},
141 	{"reconnect", sizeof("reconnect") - 1, driver_reconnect_read, driver_reconnect_write},
142 	{"report_mode", sizeof("report_mode") - 1, driver_report_read, driver_report_write},
143 	{NULL, 0, NULL, NULL}
144 };
145 
146 /* {{{ mysqli_driver_methods[]
147  */
148 const zend_function_entry mysqli_driver_methods[] = {
149 #if defined(HAVE_EMBEDDED_MYSQLI)
150 	PHP_FALIAS(embedded_server_start, mysqli_embedded_server_start, NULL)
151 	PHP_FALIAS(embedded_server_end, mysqli_embedded_server_end, NULL)
152 #endif
153 	PHP_FE_END
154 };
155 /* }}} */
156 
157 /*
158  * Local variables:
159  * tab-width: 4
160  * c-basic-offset: 4
161  * indent-tabs-mode: t
162  * End:
163  * vim600: noet sw=4 ts=4 fdm=marker
164  * vim<600: noet sw=4 ts=4
165  */
166