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.0 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_0.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: Wez Furlong <wez@php.net> |
16 +----------------------------------------------------------------------+
17 */
18
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22
23 #include "php.h"
24 #include "php_ini.h"
25 #include "ext/standard/info.h"
26 #include "pdo/php_pdo.h"
27 #include "pdo/php_pdo_driver.h"
28 #include "php_pdo_odbc.h"
29 #include "php_pdo_odbc_int.h"
30
31 /* {{{ pdo_odbc_functions[] */
32 static const zend_function_entry pdo_odbc_functions[] = {
33 PHP_FE_END
34 };
35 /* }}} */
36
37 /* {{{ pdo_odbc_deps[] */
38 static const zend_module_dep pdo_odbc_deps[] = {
39 ZEND_MOD_REQUIRED("pdo")
40 ZEND_MOD_END
41 };
42 /* }}} */
43
44 /* {{{ pdo_odbc_module_entry */
45 zend_module_entry pdo_odbc_module_entry = {
46 STANDARD_MODULE_HEADER_EX, NULL,
47 pdo_odbc_deps,
48 "PDO_ODBC",
49 pdo_odbc_functions,
50 PHP_MINIT(pdo_odbc),
51 PHP_MSHUTDOWN(pdo_odbc),
52 NULL,
53 NULL,
54 PHP_MINFO(pdo_odbc),
55 PHP_PDO_ODBC_VERSION,
56 STANDARD_MODULE_PROPERTIES
57 };
58 /* }}} */
59
60 #ifdef COMPILE_DL_PDO_ODBC
61 ZEND_GET_MODULE(pdo_odbc)
62 #endif
63
64 #ifdef SQL_ATTR_CONNECTION_POOLING
65 zend_ulong pdo_odbc_pool_on = SQL_CP_OFF;
66 zend_ulong pdo_odbc_pool_mode = SQL_CP_ONE_PER_HENV;
67 #endif
68
69 #if defined(DB2CLI_VER) && !defined(PHP_WIN32)
70 PHP_INI_BEGIN()
71 PHP_INI_ENTRY("pdo_odbc.db2_instance_name", NULL, PHP_INI_SYSTEM, NULL)
PHP_INI_END()72 PHP_INI_END()
73
74 #endif
75
76 /* {{{ PHP_MINIT_FUNCTION */
77 PHP_MINIT_FUNCTION(pdo_odbc)
78 {
79 #ifdef SQL_ATTR_CONNECTION_POOLING
80 char *pooling_val = NULL;
81 #endif
82
83 if (FAILURE == php_pdo_register_driver(&pdo_odbc_driver)) {
84 return FAILURE;
85 }
86
87 #if defined(DB2CLI_VER) && !defined(PHP_WIN32)
88 REGISTER_INI_ENTRIES();
89 {
90 char *instance = INI_STR("pdo_odbc.db2_instance_name");
91 if (instance) {
92 char *env = malloc(sizeof("DB2INSTANCE=") + strlen(instance));
93
94 php_error_docref(NULL, E_DEPRECATED, "The pdo_odbc.db2_instance_name ini directive is deprecated and will be removed in the future");
95
96 if (!env) {
97 return FAILURE;
98 }
99 strcpy(env, "DB2INSTANCE=");
100 strcat(env, instance);
101 putenv(env);
102 /* after this point, we can't free env without breaking the environment */
103 }
104 }
105 #endif
106
107 #ifdef SQL_ATTR_CONNECTION_POOLING
108 /* ugh, we don't really like .ini stuff in PDO, but since ODBC connection
109 * pooling is process wide, we can't set it from within the scope of a
110 * request without affecting others, which goes against our isolated request
111 * policy. So, we use cfg_get_string here to check it this once.
112 * */
113 if (FAILURE == cfg_get_string("pdo_odbc.connection_pooling", &pooling_val) || pooling_val == NULL) {
114 pooling_val = "strict";
115 }
116 if (strcasecmp(pooling_val, "strict") == 0 || strcmp(pooling_val, "1") == 0) {
117 pdo_odbc_pool_on = SQL_CP_ONE_PER_HENV;
118 pdo_odbc_pool_mode = SQL_CP_STRICT_MATCH;
119 } else if (strcasecmp(pooling_val, "relaxed") == 0) {
120 pdo_odbc_pool_on = SQL_CP_ONE_PER_HENV;
121 pdo_odbc_pool_mode = SQL_CP_RELAXED_MATCH;
122 } else if (*pooling_val == '\0' || strcasecmp(pooling_val, "off") == 0) {
123 pdo_odbc_pool_on = SQL_CP_OFF;
124 } else {
125 php_error_docref(NULL, E_CORE_ERROR, "Error in pdo_odbc.connection_pooling configuration. Value MUST be one of 'strict', 'relaxed' or 'off'");
126 return FAILURE;
127 }
128
129 if (pdo_odbc_pool_on != SQL_CP_OFF) {
130 SQLSetEnvAttr(SQL_NULL_HANDLE, SQL_ATTR_CONNECTION_POOLING, (void*)pdo_odbc_pool_on, 0);
131 }
132 #endif
133
134 REGISTER_PDO_CLASS_CONST_LONG("ODBC_ATTR_USE_CURSOR_LIBRARY", PDO_ODBC_ATTR_USE_CURSOR_LIBRARY);
135 REGISTER_PDO_CLASS_CONST_LONG("ODBC_ATTR_ASSUME_UTF8", PDO_ODBC_ATTR_ASSUME_UTF8);
136 REGISTER_PDO_CLASS_CONST_LONG("ODBC_SQL_USE_IF_NEEDED", SQL_CUR_USE_IF_NEEDED);
137 REGISTER_PDO_CLASS_CONST_LONG("ODBC_SQL_USE_DRIVER", SQL_CUR_USE_DRIVER);
138 REGISTER_PDO_CLASS_CONST_LONG("ODBC_SQL_USE_ODBC", SQL_CUR_USE_ODBC);
139
140 return SUCCESS;
141 }
142 /* }}} */
143
144 /* {{{ PHP_MSHUTDOWN_FUNCTION
145 */
PHP_MSHUTDOWN_FUNCTION(pdo_odbc)146 PHP_MSHUTDOWN_FUNCTION(pdo_odbc)
147 {
148 #if defined(DB2CLI_VER) && !defined(PHP_WIN32)
149 UNREGISTER_INI_ENTRIES();
150 #endif
151 php_pdo_unregister_driver(&pdo_odbc_driver);
152 return SUCCESS;
153 }
154 /* }}} */
155
156 /* {{{ PHP_MINFO_FUNCTION
157 */
PHP_MINFO_FUNCTION(pdo_odbc)158 PHP_MINFO_FUNCTION(pdo_odbc)
159 {
160 php_info_print_table_start();
161 php_info_print_table_header(2, "PDO Driver for ODBC (" PDO_ODBC_TYPE ")" , "enabled");
162 #ifdef SQL_ATTR_CONNECTION_POOLING
163 php_info_print_table_row(2, "ODBC Connection Pooling", pdo_odbc_pool_on == SQL_CP_OFF ?
164 "Disabled" : (pdo_odbc_pool_mode == SQL_CP_STRICT_MATCH ? "Enabled, strict matching" : "Enabled, relaxed matching"));
165 #else
166 php_info_print_table_row(2, "ODBC Connection Pooling", "Not supported in this build");
167 #endif
168 php_info_print_table_end();
169
170 #if defined(DB2CLI_VER) && !defined(PHP_WIN32)
171 DISPLAY_INI_ENTRIES();
172 #endif
173 }
174 /* }}} */
175
176 /*
177 * Local variables:
178 * tab-width: 4
179 * c-basic-offset: 4
180 * End:
181 * vim600: noet sw=4 ts=4 fdm=marker
182 * vim<600: noet sw=4 ts=4
183 */
184