Back to index

php5  5.3.10
pdo_odbc.c
Go to the documentation of this file.
00001 /*
00002   +----------------------------------------------------------------------+
00003   | PHP Version 5                                                        |
00004   +----------------------------------------------------------------------+
00005   | Copyright (c) 1997-2012 The PHP Group                                |
00006   +----------------------------------------------------------------------+
00007   | This source file is subject to version 3.0 of the PHP license,       |
00008   | that is bundled with this package in the file LICENSE, and is        |
00009   | available through the world-wide-web at the following url:           |
00010   | http://www.php.net/license/3_0.txt.                                  |
00011   | If you did not receive a copy of the PHP license and are unable to   |
00012   | obtain it through the world-wide-web, please send a note to          |
00013   | license@php.net so we can mail you a copy immediately.               |
00014   +----------------------------------------------------------------------+
00015   | Author: Wez Furlong <wez@php.net>                                    |
00016   +----------------------------------------------------------------------+
00017 */
00018 
00019 /* $Id: pdo_odbc.c 321634 2012-01-01 13:15:04Z felipe $ */
00020 
00021 #ifdef HAVE_CONFIG_H
00022 #include "config.h"
00023 #endif
00024 
00025 #include "php.h"
00026 #include "php_ini.h"
00027 #include "ext/standard/info.h"
00028 #include "pdo/php_pdo.h"
00029 #include "pdo/php_pdo_driver.h"
00030 #include "php_pdo_odbc.h"
00031 #include "php_pdo_odbc_int.h"
00032 
00033 /* {{{ pdo_odbc_functions[] */
00034 const function_entry pdo_odbc_functions[] = {
00035        {NULL, NULL, NULL}
00036 };
00037 /* }}} */
00038 
00039 /* {{{ pdo_odbc_deps[] */
00040 #if ZEND_MODULE_API_NO >= 20050922
00041 static const zend_module_dep pdo_odbc_deps[] = {
00042        ZEND_MOD_REQUIRED("pdo")
00043        ZEND_MOD_END
00044 };
00045 #endif
00046 /* }}} */
00047 
00048 /* {{{ pdo_odbc_module_entry */
00049 zend_module_entry pdo_odbc_module_entry = {
00050 #if ZEND_MODULE_API_NO >= 20050922
00051        STANDARD_MODULE_HEADER_EX, NULL,
00052        pdo_odbc_deps,
00053 #else
00054        STANDARD_MODULE_HEADER,
00055 #endif
00056        "PDO_ODBC",
00057        pdo_odbc_functions,
00058        PHP_MINIT(pdo_odbc),
00059        PHP_MSHUTDOWN(pdo_odbc),
00060        NULL,
00061        NULL,
00062        PHP_MINFO(pdo_odbc),
00063        "1.0.1",
00064        STANDARD_MODULE_PROPERTIES
00065 };
00066 /* }}} */
00067 
00068 #ifdef COMPILE_DL_PDO_ODBC
00069 ZEND_GET_MODULE(pdo_odbc)
00070 #endif
00071 
00072 #ifdef SQL_ATTR_CONNECTION_POOLING
00073 SQLUINTEGER pdo_odbc_pool_on = SQL_CP_OFF;
00074 SQLUINTEGER pdo_odbc_pool_mode = SQL_CP_ONE_PER_HENV;
00075 #endif
00076 
00077 #if defined(DB2CLI_VER) && !defined(PHP_WIN32)
00078 PHP_INI_BEGIN()
00079        PHP_INI_ENTRY("pdo_odbc.db2_instance_name", NULL, PHP_INI_SYSTEM, NULL)
00080 PHP_INI_END()
00081 
00082 #endif
00083 
00084 /* {{{ PHP_MINIT_FUNCTION */
00085 PHP_MINIT_FUNCTION(pdo_odbc)
00086 {
00087 #ifdef SQL_ATTR_CONNECTION_POOLING
00088        char *pooling_val = NULL;
00089 #endif
00090 
00091        if (FAILURE == php_pdo_register_driver(&pdo_odbc_driver)) {
00092               return FAILURE;
00093        }
00094 
00095 #if defined(DB2CLI_VER) && !defined(PHP_WIN32)
00096        REGISTER_INI_ENTRIES();
00097        {
00098               char *instance = INI_STR("pdo_odbc.db2_instance_name");
00099               if (instance) {
00100                      char *env = malloc(sizeof("DB2INSTANCE=") + strlen(instance));
00101                      if (!env) {
00102                             return FAILURE;
00103                      }
00104                      strcpy(env, "DB2INSTANCE=");
00105                      strcat(env, instance);
00106                      putenv(env);
00107                      /* after this point, we can't free env without breaking the environment */
00108               }
00109        }
00110 #endif
00111 
00112 #ifdef SQL_ATTR_CONNECTION_POOLING
00113        /* ugh, we don't really like .ini stuff in PDO, but since ODBC connection
00114         * pooling is process wide, we can't set it from within the scope of a
00115         * request without affecting others, which goes against our isolated request
00116         * policy.  So, we use cfg_get_string here to check it this once.
00117         * */
00118        if (FAILURE == cfg_get_string("pdo_odbc.connection_pooling", &pooling_val) || pooling_val == NULL) {
00119               pooling_val = "strict";
00120        }
00121        if (strcasecmp(pooling_val, "strict") == 0 || strcmp(pooling_val, "1") == 0) {
00122               pdo_odbc_pool_on = SQL_CP_ONE_PER_HENV;
00123               pdo_odbc_pool_mode = SQL_CP_STRICT_MATCH;
00124        } else if (strcasecmp(pooling_val, "relaxed") == 0) {
00125               pdo_odbc_pool_on = SQL_CP_ONE_PER_HENV;
00126               pdo_odbc_pool_mode = SQL_CP_RELAXED_MATCH;
00127        } else if (*pooling_val == '\0' || strcasecmp(pooling_val, "off") == 0) {
00128               pdo_odbc_pool_on = SQL_CP_OFF;
00129        } else {
00130               php_error_docref(NULL TSRMLS_CC, E_ERROR, "Error in pdo_odbc.connection_pooling configuration.  Value MUST be one of 'strict', 'relaxed' or 'off'");
00131               return FAILURE;
00132        }
00133 
00134        if (pdo_odbc_pool_on != SQL_CP_OFF) {
00135               SQLSetEnvAttr(SQL_NULL_HANDLE, SQL_ATTR_CONNECTION_POOLING, (void*)pdo_odbc_pool_on, 0);
00136        }
00137 #endif
00138 
00139        REGISTER_PDO_CLASS_CONST_LONG("ODBC_ATTR_USE_CURSOR_LIBRARY", PDO_ODBC_ATTR_USE_CURSOR_LIBRARY);
00140        REGISTER_PDO_CLASS_CONST_LONG("ODBC_ATTR_ASSUME_UTF8", PDO_ODBC_ATTR_ASSUME_UTF8);
00141        REGISTER_PDO_CLASS_CONST_LONG("ODBC_SQL_USE_IF_NEEDED", SQL_CUR_USE_IF_NEEDED);
00142        REGISTER_PDO_CLASS_CONST_LONG("ODBC_SQL_USE_DRIVER", SQL_CUR_USE_DRIVER);
00143        REGISTER_PDO_CLASS_CONST_LONG("ODBC_SQL_USE_ODBC", SQL_CUR_USE_ODBC);
00144        
00145        return SUCCESS;
00146 }
00147 /* }}} */
00148 
00149 /* {{{ PHP_MSHUTDOWN_FUNCTION
00150  */
00151 PHP_MSHUTDOWN_FUNCTION(pdo_odbc)
00152 {
00153 #if defined(DB2CLI_VER) && !defined(PHP_WIN32)
00154        UNREGISTER_INI_ENTRIES();
00155 #endif
00156        php_pdo_unregister_driver(&pdo_odbc_driver);
00157        return SUCCESS;
00158 }
00159 /* }}} */
00160 
00161 /* {{{ PHP_MINFO_FUNCTION
00162  */
00163 PHP_MINFO_FUNCTION(pdo_odbc)
00164 {
00165        php_info_print_table_start();
00166        php_info_print_table_header(2, "PDO Driver for ODBC (" PDO_ODBC_TYPE ")" , "enabled");
00167 #ifdef SQL_ATTR_CONNECTION_POOLING
00168        php_info_print_table_row(2, "ODBC Connection Pooling",  pdo_odbc_pool_on == SQL_CP_OFF ?
00169                      "Disabled" : (pdo_odbc_pool_mode == SQL_CP_STRICT_MATCH ? "Enabled, strict matching" : "Enabled, relaxed matching"));
00170 #else
00171        php_info_print_table_row(2, "ODBC Connection Pooling", "Not supported in this build");
00172 #endif
00173        php_info_print_table_end();
00174 
00175 #if defined(DB2CLI_VER) && !defined(PHP_WIN32)
00176        DISPLAY_INI_ENTRIES();
00177 #endif
00178 }
00179 /* }}} */
00180 
00181 /*
00182  * Local variables:
00183  * tab-width: 4
00184  * c-basic-offset: 4
00185  * End:
00186  * vim600: noet sw=4 ts=4 fdm=marker
00187  * vim<600: noet sw=4 ts=4
00188  */