1 /*
2 +----------------------------------------------------------------------+
3 | PHP Version 5 |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1997-2013 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 /* {{{ PHP_INI_BEGIN
61 */
62 PHP_INI_BEGIN()
63 #ifndef PHP_WIN32
64 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)
65 #endif
66 #if PDO_DBG_ENABLED
67 STD_PHP_INI_ENTRY("pdo_mysql.debug", NULL, PHP_INI_SYSTEM, OnUpdateString, debug, zend_pdo_mysql_globals, pdo_mysql_globals)
68 #endif
69 PHP_INI_END()
70 /* }}} */
71
72 /* true global environment */
73
74 /* {{{ PHP_MINIT_FUNCTION
75 */
76 static PHP_MINIT_FUNCTION(pdo_mysql)
77 {
78 REGISTER_INI_ENTRIES();
79
80 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_USE_BUFFERED_QUERY", (long)PDO_MYSQL_ATTR_USE_BUFFERED_QUERY);
81 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_LOCAL_INFILE", (long)PDO_MYSQL_ATTR_LOCAL_INFILE);
82 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_INIT_COMMAND", (long)PDO_MYSQL_ATTR_INIT_COMMAND);
83 #ifndef PDO_USE_MYSQLND
84 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_MAX_BUFFER_SIZE", (long)PDO_MYSQL_ATTR_MAX_BUFFER_SIZE);
85 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_READ_DEFAULT_FILE", (long)PDO_MYSQL_ATTR_READ_DEFAULT_FILE);
86 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_READ_DEFAULT_GROUP", (long)PDO_MYSQL_ATTR_READ_DEFAULT_GROUP);
87 #endif
88 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_COMPRESS", (long)PDO_MYSQL_ATTR_COMPRESS);
89 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_DIRECT_QUERY", (long)PDO_MYSQL_ATTR_DIRECT_QUERY);
90 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_FOUND_ROWS", (long)PDO_MYSQL_ATTR_FOUND_ROWS);
91 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_IGNORE_SPACE", (long)PDO_MYSQL_ATTR_IGNORE_SPACE);
92 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_KEY", (long)PDO_MYSQL_ATTR_SSL_KEY);
93 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_CERT", (long)PDO_MYSQL_ATTR_SSL_CERT);
94 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_CA", (long)PDO_MYSQL_ATTR_SSL_CA);
95 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_CAPATH", (long)PDO_MYSQL_ATTR_SSL_CAPATH);
96 REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_CIPHER", (long)PDO_MYSQL_ATTR_SSL_CIPHER);
97 return php_pdo_register_driver(&pdo_mysql_driver);
98 }
99 /* }}} */
100
101 /* {{{ PHP_MSHUTDOWN_FUNCTION
102 */
PHP_MSHUTDOWN_FUNCTION(pdo_mysql)103 static PHP_MSHUTDOWN_FUNCTION(pdo_mysql)
104 {
105 php_pdo_unregister_driver(&pdo_mysql_driver);
106 #if PDO_USE_MYSQLND
107 UNREGISTER_INI_ENTRIES();
108 #endif
109
110 return SUCCESS;
111 }
112 /* }}} */
113
114 /* {{{ PHP_MINFO_FUNCTION
115 */
PHP_MINFO_FUNCTION(pdo_mysql)116 static PHP_MINFO_FUNCTION(pdo_mysql)
117 {
118 php_info_print_table_start();
119
120 php_info_print_table_header(2, "PDO Driver for MySQL", "enabled");
121 php_info_print_table_row(2, "Client API version", mysql_get_client_info());
122
123 php_info_print_table_end();
124
125 #ifndef PHP_WIN32
126 DISPLAY_INI_ENTRIES();
127 #endif
128 }
129 /* }}} */
130
131
132 #if PDO_USE_MYSQLND && PDO_DBG_ENABLED
133 /* {{{ PHP_RINIT_FUNCTION
134 */
PHP_RINIT_FUNCTION(pdo_mysql)135 static PHP_RINIT_FUNCTION(pdo_mysql)
136 {
137 if (PDO_MYSQL_G(debug)) {
138 MYSQLND_DEBUG *dbg = mysqlnd_debug_init(mysqlnd_debug_std_no_trace_funcs TSRMLS_CC);
139 if (!dbg) {
140 return FAILURE;
141 }
142 dbg->m->set_mode(dbg, PDO_MYSQL_G(debug));
143 PDO_MYSQL_G(dbg) = dbg;
144 }
145
146 return SUCCESS;
147 }
148 /* }}} */
149
150 /* {{{ PHP_RSHUTDOWN_FUNCTION
151 */
PHP_RSHUTDOWN_FUNCTION(pdo_mysql)152 static PHP_RSHUTDOWN_FUNCTION(pdo_mysql)
153 {
154 MYSQLND_DEBUG *dbg = PDO_MYSQL_G(dbg);
155 PDO_DBG_ENTER("RSHUTDOWN");
156 if (dbg) {
157 dbg->m->close(dbg);
158 dbg->m->free_handle(dbg);
159 PDO_MYSQL_G(dbg) = NULL;
160 }
161
162 return SUCCESS;
163 }
164 /* }}} */
165 #endif
166
167 /* {{{ PHP_GINIT_FUNCTION
168 */
PHP_GINIT_FUNCTION(pdo_mysql)169 static PHP_GINIT_FUNCTION(pdo_mysql)
170 {
171 #ifndef PHP_WIN32
172 pdo_mysql_globals->default_socket = NULL;
173 #endif
174 #if PDO_DBG_ENABLED
175 pdo_mysql_globals->debug = NULL; /* The actual string */
176 pdo_mysql_globals->dbg = NULL; /* The DBG object*/
177 #endif
178 }
179 /* }}} */
180
181 /* {{{ pdo_mysql_functions[] */
182 const zend_function_entry pdo_mysql_functions[] = {
183 PHP_FE_END
184 };
185 /* }}} */
186
187 /* {{{ pdo_mysql_deps[] */
188 #if ZEND_MODULE_API_NO >= 20050922
189 static const zend_module_dep pdo_mysql_deps[] = {
190 ZEND_MOD_REQUIRED("pdo")
191 #ifdef PDO_USE_MYSQLND
192 ZEND_MOD_REQUIRED("mysqlnd")
193 #endif
194 ZEND_MOD_END
195 };
196 #endif
197 /* }}} */
198
199 /* {{{ pdo_mysql_module_entry */
200 zend_module_entry pdo_mysql_module_entry = {
201 STANDARD_MODULE_HEADER_EX, NULL,
202 pdo_mysql_deps,
203 "pdo_mysql",
204 pdo_mysql_functions,
205 PHP_MINIT(pdo_mysql),
206 PHP_MSHUTDOWN(pdo_mysql),
207 #if PDO_USE_MYSQLND && PDO_DBG_ENABLED
208 PHP_RINIT(pdo_mysql),
209 PHP_RSHUTDOWN(pdo_mysql),
210 #else
211 NULL,
212 NULL,
213 #endif
214 PHP_MINFO(pdo_mysql),
215 "1.0.2",
216 PHP_MODULE_GLOBALS(pdo_mysql),
217 PHP_GINIT(pdo_mysql),
218 NULL,
219 NULL,
220 STANDARD_MODULE_PROPERTIES_EX
221 };
222 /* }}} */
223
224
225 /*
226 * Local variables:
227 * tab-width: 4
228 * c-basic-offset: 4
229 * End:
230 * vim600: noet sw=4 ts=4 fdm=marker
231 * vim<600: noet sw=4 ts=4
232 */
233