xref: /PHP-5.4/ext/mysqli/mysqli_driver.c (revision c0d060f5)
1 /*
2   +----------------------------------------------------------------------+
3   | PHP Version 5                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 1997-2014 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 int name(mysqli_object *obj, zval **retval TSRMLS_DC) \
34 { \
35 	MAKE_STD_ZVAL(*retval); \
36 	ZVAL_BOOL(*retval, MyG(value)); \
37 	return SUCCESS; \
38 } \
39 
40 #define MAP_PROPERTY_MYG_BOOL_WRITE(name, value) \
41 static int name(mysqli_object *obj, zval *value TSRMLS_DC) \
42 { \
43 	MyG(value) = Z_LVAL_P(value) > 0; \
44 	return SUCCESS; \
45 } \
46 
47 #define MAP_PROPERTY_MYG_LONG_READ(name, value) \
48 static int name(mysqli_object *obj, zval **retval TSRMLS_DC) \
49 { \
50 	MAKE_STD_ZVAL(*retval); \
51 	ZVAL_LONG(*retval, MyG(value)); \
52 	return SUCCESS; \
53 } \
54 
55 #define MAP_PROPERTY_MYG_LONG_WRITE(name, value) \
56 static int name(mysqli_object *obj, zval *value TSRMLS_DC) \
57 { \
58 	MyG(value) = Z_LVAL_P(value); \
59 	return SUCCESS; \
60 } \
61 
62 #define MAP_PROPERTY_MYG_STRING_READ(name, value) \
63 static int name(mysqli_object *obj, zval **retval TSRMLS_DC) \
64 { \
65 	MAKE_STD_ZVAL(*retval); \
66 	ZVAL_STRING(*retval, MyG(value), 1); \
67 	return SUCCESS; \
68 } \
69 
70 #define MAP_PROPERTY_MYG_STRING_WRITE(name, value) \
71 static int name(mysqli_object *obj, zval *value TSRMLS_DC) \
72 { \
73 	MyG(value) = Z_STRVAL_P(value); \
74 	return SUCCESS; \
75 } \
76 
77 /* {{{ property driver_report_write */
driver_report_write(mysqli_object * obj,zval * value TSRMLS_DC)78 static int driver_report_write(mysqli_object *obj, zval *value TSRMLS_DC)
79 {
80 	MyG(report_mode) = Z_LVAL_P(value);
81 	/*FIXME*/
82 	/* zend_replace_error_handling(MyG(report_mode) & MYSQLI_REPORT_STRICT ? EH_THROW : EH_NORMAL, NULL, NULL TSRMLS_CC); */
83 	return SUCCESS;
84 }
85 /* }}} */
86 
87 /* {{{ property driver_embedded_read */
driver_embedded_read(mysqli_object * obj,zval ** retval TSRMLS_DC)88 static int driver_embedded_read(mysqli_object *obj, zval **retval TSRMLS_DC)
89 {
90 	MAKE_STD_ZVAL(*retval);
91 #ifdef HAVE_EMBEDDED_MYSQLI
92 	ZVAL_BOOL(*retval, 1);
93 #else
94 	ZVAL_BOOL(*retval, 0);
95 #endif
96 	return SUCCESS;
97 }
98 /* }}} */
99 
100 /* {{{ property driver_client_version_read */
driver_client_version_read(mysqli_object * obj,zval ** retval TSRMLS_DC)101 static int driver_client_version_read(mysqli_object *obj, zval **retval TSRMLS_DC)
102 {
103 	MAKE_STD_ZVAL(*retval);
104 	ZVAL_LONG(*retval, MYSQL_VERSION_ID);
105 	return SUCCESS;
106 }
107 /* }}} */
108 
109 /* {{{ property driver_client_info_read */
driver_client_info_read(mysqli_object * obj,zval ** retval TSRMLS_DC)110 static int driver_client_info_read(mysqli_object *obj, zval **retval TSRMLS_DC)
111 {
112 	MAKE_STD_ZVAL(*retval);
113 	ZVAL_STRING(*retval, (char *)mysql_get_client_info(), 1);
114 	return SUCCESS;
115 }
116 /* }}} */
117 
118 /* {{{ property driver_driver_version_read */
driver_driver_version_read(mysqli_object * obj,zval ** retval TSRMLS_DC)119 static int driver_driver_version_read(mysqli_object *obj, zval **retval TSRMLS_DC)
120 {
121 	MAKE_STD_ZVAL(*retval);
122 	ZVAL_LONG(*retval, MYSQLI_VERSION_ID);
123 	return SUCCESS;
124 }
125 /* }}} */
126 
MAP_PROPERTY_MYG_BOOL_READ(driver_reconnect_read,reconnect)127 MAP_PROPERTY_MYG_BOOL_READ(driver_reconnect_read, reconnect)
128 MAP_PROPERTY_MYG_BOOL_WRITE(driver_reconnect_write, reconnect)
129 MAP_PROPERTY_MYG_LONG_READ(driver_report_read, report_mode)
130 
131 ZEND_FUNCTION(mysqli_driver_construct)
132 {
133 #if G0
134 	MYSQLI_RESOURCE 	*mysqli_resource;
135 
136 	mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
137 	mysqli_resource->ptr = 1;
138 	mysqli_resource->status = (ZEND_NUM_ARGS() == 1) ? MYSQLI_STATUS_INITIALIZED : MYSQLI_STATUS_VALID;
139 	((mysqli_object *) zend_object_store_get_object(getThis() TSRMLS_CC))->ptr = mysqli_resource;
140 #endif
141 }
142 
143 const mysqli_property_entry mysqli_driver_property_entries[] = {
144 	{"client_info", sizeof("client_info") - 1, driver_client_info_read, NULL},
145 	{"client_version", sizeof("client_version") - 1, driver_client_version_read, NULL},
146 	{"driver_version", sizeof("driver_version") - 1, driver_driver_version_read, NULL},
147 	{"embedded", sizeof("embedded") - 1, driver_embedded_read, NULL},
148 	{"reconnect", sizeof("reconnect") - 1, driver_reconnect_read, driver_reconnect_write},
149 	{"report_mode", sizeof("report_mode") - 1, driver_report_read, driver_report_write},
150 	{NULL, 0, NULL, NULL}
151 };
152 
153 /* {{{ mysqli_warning_property_info_entries */
154 const zend_property_info mysqli_driver_property_info_entries[] = {
155 	{ZEND_ACC_PUBLIC, "client_info",	sizeof("client_info") - 1,		-1, 0, NULL, 0, NULL},
156 	{ZEND_ACC_PUBLIC, "client_version",	sizeof("client_version") - 1,	-1, 0, NULL, 0, NULL},
157 	{ZEND_ACC_PUBLIC, "driver_version",	sizeof("driver_version") - 1,	-1, 0, NULL, 0, NULL},
158 	{ZEND_ACC_PUBLIC, "embedded",		sizeof("embedded") - 1,			-1, 0, NULL, 0, NULL},
159 	{ZEND_ACC_PUBLIC, "reconnect",		sizeof("reconnect") - 1,		-1, 0, NULL, 0, NULL},
160 	{ZEND_ACC_PUBLIC, "report_mode",	sizeof("report_mode") - 1,		-1, 0, NULL, 0, NULL},
161 	{0,					NULL, 			0,								-1, 0, NULL, 0, NULL},
162 };
163 /* }}} */
164 
165 
166 /* {{{ mysqli_driver_methods[]
167  */
168 const zend_function_entry mysqli_driver_methods[] = {
169 #if defined(HAVE_EMBEDDED_MYSQLI)
170 	PHP_FALIAS(embedded_server_start, mysqli_embedded_server_start, NULL)
171 	PHP_FALIAS(embedded_server_end, mysqli_embedded_server_end, NULL)
172 #endif
173 	{NULL, NULL, NULL}
174 };
175 /* }}} */
176 
177 /*
178  * Local variables:
179  * tab-width: 4
180  * c-basic-offset: 4
181  * indent-tabs-mode: t
182  * End:
183  * vim600: noet sw=4 ts=4 fdm=marker
184  * vim<600: noet sw=4 ts=4
185  */
186