pdo_oci.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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.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: Wez Furlong <wez@php.net> |
  16. +----------------------------------------------------------------------+
  17. */
  18. #ifdef HAVE_CONFIG_H
  19. #include "config.h"
  20. #endif
  21. #include "php.h"
  22. #include "php_ini.h"
  23. #include "ext/standard/info.h"
  24. #include "pdo/php_pdo.h"
  25. #include "pdo/php_pdo_driver.h"
  26. #include "php_pdo_oci.h"
  27. #include "php_pdo_oci_int.h"
  28. #ifdef ZTS
  29. #include <TSRM/TSRM.h>
  30. #endif
  31. /* {{{ pdo_oci_functions[] */
  32. static const zend_function_entry pdo_oci_functions[] = {
  33. PHP_FE_END
  34. };
  35. /* }}} */
  36. /* {{{ pdo_oci_module_entry */
  37. static const zend_module_dep pdo_oci_deps[] = {
  38. ZEND_MOD_REQUIRED("pdo")
  39. ZEND_MOD_END
  40. };
  41. zend_module_entry pdo_oci_module_entry = {
  42. STANDARD_MODULE_HEADER_EX, NULL,
  43. pdo_oci_deps,
  44. "PDO_OCI",
  45. pdo_oci_functions,
  46. PHP_MINIT(pdo_oci),
  47. PHP_MSHUTDOWN(pdo_oci),
  48. PHP_RINIT(pdo_oci),
  49. NULL,
  50. PHP_MINFO(pdo_oci),
  51. PHP_PDO_OCI_VERSION,
  52. STANDARD_MODULE_PROPERTIES
  53. };
  54. /* }}} */
  55. #ifdef COMPILE_DL_PDO_OCI
  56. ZEND_GET_MODULE(pdo_oci)
  57. #endif
  58. const ub4 PDO_OCI_INIT_MODE =
  59. #if 0 && defined(OCI_SHARED)
  60. /* shared mode is known to be bad for PHP */
  61. OCI_SHARED
  62. #else
  63. OCI_DEFAULT
  64. #endif
  65. #ifdef OCI_OBJECT
  66. |OCI_OBJECT
  67. #endif
  68. #ifdef ZTS
  69. |OCI_THREADED
  70. #endif
  71. ;
  72. /* true global environment */
  73. OCIEnv *pdo_oci_Env = NULL;
  74. #ifdef ZTS
  75. /* lock for pdo_oci_Env initialization */
  76. static MUTEX_T pdo_oci_env_mutex;
  77. #endif
  78. /* {{{ PHP_MINIT_FUNCTION
  79. */
  80. PHP_MINIT_FUNCTION(pdo_oci)
  81. {
  82. REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_ACTION", (zend_long)PDO_OCI_ATTR_ACTION);
  83. REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_CLIENT_INFO", (zend_long)PDO_OCI_ATTR_CLIENT_INFO);
  84. REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_CLIENT_IDENTIFIER", (zend_long)PDO_OCI_ATTR_CLIENT_IDENTIFIER);
  85. REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_MODULE", (zend_long)PDO_OCI_ATTR_MODULE);
  86. php_pdo_register_driver(&pdo_oci_driver);
  87. // Defer OCI init to PHP_RINIT_FUNCTION because with php-fpm,
  88. // NLS_LANG is not yet available here.
  89. #ifdef ZTS
  90. pdo_oci_env_mutex = tsrm_mutex_alloc();
  91. #endif
  92. return SUCCESS;
  93. }
  94. /* }}} */
  95. /* {{{ PHP_RINIT_FUNCTION
  96. */
  97. PHP_RINIT_FUNCTION(pdo_oci)
  98. {
  99. if (!pdo_oci_Env) {
  100. #ifdef ZTS
  101. tsrm_mutex_lock(pdo_oci_env_mutex);
  102. if (!pdo_oci_Env) { // double-checked locking idiom
  103. #endif
  104. #if HAVE_OCIENVCREATE
  105. OCIEnvCreate(&pdo_oci_Env, PDO_OCI_INIT_MODE, NULL, NULL, NULL, NULL, 0, NULL);
  106. #else
  107. OCIInitialize(PDO_OCI_INIT_MODE, NULL, NULL, NULL, NULL);
  108. OCIEnvInit(&pdo_oci_Env, OCI_DEFAULT, 0, NULL);
  109. #endif
  110. #ifdef ZTS
  111. }
  112. tsrm_mutex_unlock(pdo_oci_env_mutex);
  113. #endif
  114. }
  115. return SUCCESS;
  116. }
  117. /* }}} */
  118. /* {{{ PHP_MSHUTDOWN_FUNCTION
  119. */
  120. PHP_MSHUTDOWN_FUNCTION(pdo_oci)
  121. {
  122. php_pdo_unregister_driver(&pdo_oci_driver);
  123. if (pdo_oci_Env) {
  124. OCIHandleFree((dvoid*)pdo_oci_Env, OCI_HTYPE_ENV);
  125. }
  126. #ifdef ZTS
  127. tsrm_mutex_free(pdo_oci_env_mutex);
  128. #endif
  129. return SUCCESS;
  130. }
  131. /* }}} */
  132. /* {{{ PHP_MINFO_FUNCTION
  133. */
  134. PHP_MINFO_FUNCTION(pdo_oci)
  135. {
  136. php_info_print_table_start();
  137. php_info_print_table_header(2, "PDO Driver for OCI 8 and later", "enabled");
  138. php_info_print_table_end();
  139. }
  140. /* }}} */
  141. /*
  142. * Local variables:
  143. * tab-width: 4
  144. * c-basic-offset: 4
  145. * End:
  146. * vim600: noet sw=4 ts=4 fdm=marker
  147. * vim<600: noet sw=4 ts=4
  148. */