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: George Schlossnagle <george@omniti.com> |
16 | Johannes Schlueter <johannes@mysql.com> |
17 +----------------------------------------------------------------------+
18 */
19
20 /* $Id$ */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include "php.h"
27 #include "php_ini.h"
28 #include "ext/standard/info.h"
29 #include "pdo/php_pdo.h"
30 #include "pdo/php_pdo_driver.h"
31 #include "php_pdo_mysql.h"
32 #include "php_pdo_mysql_int.h"
33
34 #ifdef COMPILE_DL_PDO_MYSQL
35 ZEND_GET_MODULE(pdo_mysql)
36 #endif
37
ZEND_DECLARE_MODULE_GLOBALS(pdo_mysql)38 ZEND_DECLARE_MODULE_GLOBALS(pdo_mysql)
39
40 /*
41 The default socket location is sometimes defined by configure.
42 With libmysql `mysql_config --socket` will fill PDO_MYSQL_UNIX_ADDR
43 and the user can use --with-mysql-sock=SOCKET which will fill
44 PDO_MYSQL_UNIX_ADDR. If both aren't set we're using mysqlnd and use
45 /tmp/mysql.sock as default on *nix and NULL for Windows (default
46 named pipe name is set in mysqlnd).
47 */
48 #ifndef PDO_MYSQL_UNIX_ADDR
49 # ifdef PHP_MYSQL_UNIX_SOCK_ADDR
50 # define PDO_MYSQL_UNIX_ADDR PHP_MYSQL_UNIX_SOCK_ADDR
51 # else
52 # if !PHP_WIN32
53 # define PDO_MYSQL_UNIX_ADDR "/tmp/mysql.sock"
54 # else
55 # define PDO_MYSQL_UNIX_ADDR NULL
56 # endif
57 # endif
58 #endif
59
60 #ifdef PDO_USE_MYSQLND
61 #include "ext/mysqlnd/mysqlnd_reverse_api.h"
62 static MYSQLND * pdo_mysql_convert_zv_to_mysqlnd(zval * zv TSRMLS_DC)
63 {
64 if (Z_TYPE_P(zv) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zv), php_pdo_get_dbh_ce() TSRMLS_CC)) {
65 pdo_dbh_t * dbh = zend_object_store_get_object(zv TSRMLS_CC);
66
67 if (!dbh) {
68 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to retrieve handle from object store");
69 return NULL;
70 }
71
72 if (dbh->driver != &pdo_mysql_driver) {
73 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Provided PDO instance is not using MySQL but %s", dbh->driver->driver_name);
74 return NULL;
75 }
76
77 return ((pdo_mysql_db_handle *)dbh->driver_data)->server;
78 }
79 return NULL;
80 }
81
82 static MYSQLND_REVERSE_API pdo_mysql_reverse_api = {
83 &pdo_mysql_module_entry,
84 pdo_mysql_convert_zv_to_mysqlnd
85 };
86 #endif
87
88
89 /* {{{ PHP_INI_BEGIN
90 */
91 PHP_INI_BEGIN()
92 #ifndef PHP_WIN32
93 STD_PHP_INI_ENTRY("pdo_mysql.default_socket", PDO_MYSQL_UNIX_ADDR, PHP_INI_SYSTEM, OnUpdateStringUnempty, default_socket, zend_pdo_mysql_globals, pdo_mysql_globals)
94 #endif
95 #if PDO_DBG_ENABLED
96 STD_PHP_INI_ENTRY("pdo_mysql.debug", NULL, PHP_INI_SYSTEM, OnUpdateString, debug, zend_pdo_mysql_globals, pdo_mysql_globals)
97 #endif
PHP_INI_END()98 PHP_INI_END()
99 /* }}} */
100
101 /* true global environment */
102
103 /* {{{ PHP_MINIT_FUNCTION
104 */
105 static PHP_MINIT_FUNCTION(pdo_mysql)
106 {
107 REGISTER_INI_ENTRIES();
108
109 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_USE_BUFFERED_QUERY", (long)PDO_MYSQL_ATTR_USE_BUFFERED_QUERY);
110 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_LOCAL_INFILE", (long)PDO_MYSQL_ATTR_LOCAL_INFILE);
111 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_INIT_COMMAND", (long)PDO_MYSQL_ATTR_INIT_COMMAND);
112 #ifndef PDO_USE_MYSQLND
113 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_MAX_BUFFER_SIZE", (long)PDO_MYSQL_ATTR_MAX_BUFFER_SIZE);
114 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_READ_DEFAULT_FILE", (long)PDO_MYSQL_ATTR_READ_DEFAULT_FILE);
115 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_READ_DEFAULT_GROUP", (long)PDO_MYSQL_ATTR_READ_DEFAULT_GROUP);
116 #endif
117 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_COMPRESS", (long)PDO_MYSQL_ATTR_COMPRESS);
118 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_DIRECT_QUERY", (long)PDO_MYSQL_ATTR_DIRECT_QUERY);
119 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_FOUND_ROWS", (long)PDO_MYSQL_ATTR_FOUND_ROWS);
120 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_IGNORE_SPACE", (long)PDO_MYSQL_ATTR_IGNORE_SPACE);
121 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_KEY", (long)PDO_MYSQL_ATTR_SSL_KEY);
122 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_CERT", (long)PDO_MYSQL_ATTR_SSL_CERT);
123 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_CA", (long)PDO_MYSQL_ATTR_SSL_CA);
124 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_CAPATH", (long)PDO_MYSQL_ATTR_SSL_CAPATH);
125 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_CIPHER", (long)PDO_MYSQL_ATTR_SSL_CIPHER);
126
127 #ifdef PDO_USE_MYSQLND
128 mysqlnd_reverse_api_register_api(&pdo_mysql_reverse_api TSRMLS_CC);
129 #endif
130
131 return php_pdo_register_driver(&pdo_mysql_driver);
132 }
133 /* }}} */
134
135 /* {{{ PHP_MSHUTDOWN_FUNCTION
136 */
PHP_MSHUTDOWN_FUNCTION(pdo_mysql)137 static PHP_MSHUTDOWN_FUNCTION(pdo_mysql)
138 {
139 php_pdo_unregister_driver(&pdo_mysql_driver);
140 #if PDO_USE_MYSQLND
141 UNREGISTER_INI_ENTRIES();
142 #endif
143
144 return SUCCESS;
145 }
146 /* }}} */
147
148 /* {{{ PHP_MINFO_FUNCTION
149 */
PHP_MINFO_FUNCTION(pdo_mysql)150 static PHP_MINFO_FUNCTION(pdo_mysql)
151 {
152 php_info_print_table_start();
153
154 php_info_print_table_header(2, "PDO Driver for MySQL", "enabled");
155 php_info_print_table_row(2, "Client API version", mysql_get_client_info());
156
157 php_info_print_table_end();
158
159 #ifndef PHP_WIN32
160 DISPLAY_INI_ENTRIES();
161 #endif
162 }
163 /* }}} */
164
165
166 #if PDO_USE_MYSQLND && PDO_DBG_ENABLED
167 /* {{{ PHP_RINIT_FUNCTION
168 */
PHP_RINIT_FUNCTION(pdo_mysql)169 static PHP_RINIT_FUNCTION(pdo_mysql)
170 {
171 if (PDO_MYSQL_G(debug)) {
172 MYSQLND_DEBUG *dbg = mysqlnd_debug_init(mysqlnd_debug_std_no_trace_funcs TSRMLS_CC);
173 if (!dbg) {
174 return FAILURE;
175 }
176 dbg->m->set_mode(dbg, PDO_MYSQL_G(debug));
177 PDO_MYSQL_G(dbg) = dbg;
178 }
179
180 return SUCCESS;
181 }
182 /* }}} */
183
184 /* {{{ PHP_RSHUTDOWN_FUNCTION
185 */
PHP_RSHUTDOWN_FUNCTION(pdo_mysql)186 static PHP_RSHUTDOWN_FUNCTION(pdo_mysql)
187 {
188 MYSQLND_DEBUG *dbg = PDO_MYSQL_G(dbg);
189 PDO_DBG_ENTER("RSHUTDOWN");
190 if (dbg) {
191 dbg->m->close(dbg);
192 dbg->m->free_handle(dbg);
193 PDO_MYSQL_G(dbg) = NULL;
194 }
195
196 return SUCCESS;
197 }
198 /* }}} */
199 #endif
200
201 /* {{{ PHP_GINIT_FUNCTION
202 */
PHP_GINIT_FUNCTION(pdo_mysql)203 static PHP_GINIT_FUNCTION(pdo_mysql)
204 {
205 #ifndef PHP_WIN32
206 pdo_mysql_globals->default_socket = NULL;
207 #endif
208 #if PDO_DBG_ENABLED
209 pdo_mysql_globals->debug = NULL; /* The actual string */
210 pdo_mysql_globals->dbg = NULL; /* The DBG object*/
211 #endif
212 }
213 /* }}} */
214
215 /* {{{ pdo_mysql_functions[] */
216 const zend_function_entry pdo_mysql_functions[] = {
217 PHP_FE_END
218 };
219 /* }}} */
220
221 /* {{{ pdo_mysql_deps[] */
222 #if ZEND_MODULE_API_NO >= 20050922
223 static const zend_module_dep pdo_mysql_deps[] = {
224 ZEND_MOD_REQUIRED("pdo")
225 #ifdef PDO_USE_MYSQLND
226 ZEND_MOD_REQUIRED("mysqlnd")
227 #endif
228 ZEND_MOD_END
229 };
230 #endif
231 /* }}} */
232
233 /* {{{ pdo_mysql_module_entry */
234 zend_module_entry pdo_mysql_module_entry = {
235 STANDARD_MODULE_HEADER_EX, NULL,
236 pdo_mysql_deps,
237 "pdo_mysql",
238 pdo_mysql_functions,
239 PHP_MINIT(pdo_mysql),
240 PHP_MSHUTDOWN(pdo_mysql),
241 #if PDO_USE_MYSQLND && PDO_DBG_ENABLED
242 PHP_RINIT(pdo_mysql),
243 PHP_RSHUTDOWN(pdo_mysql),
244 #else
245 NULL,
246 NULL,
247 #endif
248 PHP_MINFO(pdo_mysql),
249 "1.0.2",
250 PHP_MODULE_GLOBALS(pdo_mysql),
251 PHP_GINIT(pdo_mysql),
252 NULL,
253 NULL,
254 STANDARD_MODULE_PROPERTIES_EX
255 };
256 /* }}} */
257
258
259 /*
260 * Local variables:
261 * tab-width: 4
262 * c-basic-offset: 4
263 * End:
264 * vim600: noet sw=4 ts=4 fdm=marker
265 * vim<600: noet sw=4 ts=4
266 */
267