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