1999-04-21 22:49:16 +00:00
/*
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2019-01-30 09:03:12 +00:00
| Copyright ( c ) The PHP Group |
1999-04-21 22:49:16 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2006-01-01 12:51:34 +00:00
| This source file is subject to version 3.01 of the PHP license , |
1999-07-16 13:13:16 +00:00
| that is bundled with this package in the file LICENSE , and is |
2003-06-10 20:04:29 +00:00
| available through the world - wide - web at the following url : |
2021-05-06 10:16:35 +00:00
| https : //www.php.net/license/3_01.txt |
1999-07-16 13:13:16 +00:00
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world - wide - web , please send a note to |
| license @ php . net so we can mail you a copy immediately . |
1999-04-21 22:49:16 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2013-09-27 04:12:11 +00:00
| Authors : Stig Sæther Bakken < ssb @ php . net > |
2002-02-28 08:29:35 +00:00
| Thies C . Arntzen < thies @ thieso . net > |
2003-01-29 18:31:48 +00:00
| Maxim Maletsky < maxim @ maxim . cx > |
2002-02-28 08:29:35 +00:00
| |
2001-04-13 14:43:39 +00:00
| Collection support by Andy Sautins < asautins @ veripost . net > |
2002-02-28 08:29:35 +00:00
| Temporary LOB support by David Benson < dbenson @ mancala . com > |
2003-12-16 10:29:11 +00:00
| ZTS per process OCIPLogon by Harald Radi < harald . radi @ nme . at > |
2005-12-01 13:39:48 +00:00
| |
| Redesigned by : Antony Dovgal < antony @ zend . com > |
2018-11-01 16:35:32 +00:00
| Andi Gutmans < andi @ php . net > |
2005-12-01 13:39:48 +00:00
| Wez Furlong < wez @ omniti . com > |
1999-04-21 22:49:16 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2005-12-01 13:39:48 +00:00
*/
2000-02-01 14:39:59 +00:00
2001-05-24 10:07:29 +00:00
# ifdef HAVE_CONFIG_H
# include "config.h"
# endif
1999-04-21 22:49:16 +00:00
# include "php.h"
2000-04-06 21:07:44 +00:00
# include "ext/standard/info.h"
2003-12-16 10:29:11 +00:00
# include "php_ini.h"
2022-04-12 12:47:46 +00:00
# include "zend_attributes.h"
2014-09-20 20:42:02 +00:00
# include "zend_smart_str.h"
1999-04-24 18:54:02 +00:00
2020-05-20 14:20:33 +00:00
# ifdef HAVE_OCI8
1999-07-08 14:12:07 +00:00
2021-11-28 01:06:25 +00:00
/* Note to maintainers: config.m4 should/does check the minimum PHP version so
2021-12-12 02:32:34 +00:00
* the below checks are obsolete - but are kept ' just in case ' . Also bump the
* minimum version in package . xml , as appropriate . */
2021-11-28 01:06:25 +00:00
2013-10-08 00:23:11 +00:00
/* PHP 5.2 is the minimum supported version for OCI8 2.0 */
# if PHP_MAJOR_VERSION < 5 || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION <= 1)
# error Use PHP OCI8 1.4 for your version of PHP
2015-12-12 05:07:57 +00:00
# elif PHP_MAJOR_VERSION < 7
2015-09-11 23:10:32 +00:00
/* PHP 7 is the minimum supported version for OCI8 2.1 */
# error Use PHP OCI8 2.0 for your version of PHP
2020-07-15 04:35:14 +00:00
# elif PHP_MAJOR_VERSION < 8
2021-11-28 01:06:25 +00:00
/* PHP 8 is the minimum supported version for OCI8 3 */
2020-07-15 04:35:14 +00:00
# error Use PHP OCI8 2.2 for your version of PHP
2021-11-28 01:06:25 +00:00
# elif PHP_MAJOR_VERSION == 8 && PHP_MINOR_VERSION < 1
# error Use PHP OCI8 3.0 for your version of PHP
2015-09-11 23:10:32 +00:00
# endif
1999-12-04 19:19:57 +00:00
# include "php_oci8.h"
2005-12-01 13:39:48 +00:00
# include "php_oci8_int.h"
2006-08-05 20:56:43 +00:00
# include "zend_hash.h"
1999-04-21 22:49:16 +00:00
2005-12-01 13:39:48 +00:00
ZEND_DECLARE_MODULE_GLOBALS ( oci )
2006-06-15 18:33:09 +00:00
static PHP_GINIT_FUNCTION ( oci ) ;
2009-03-09 20:09:07 +00:00
static PHP_GSHUTDOWN_FUNCTION ( oci ) ;
2003-12-16 10:29:11 +00:00
2008-01-31 01:33:30 +00:00
/* Allow PHP 5.3 branch to be used in PECL for 5.x compatible builds */
# ifndef Z_ADDREF_P
# define Z_ADDREF_P(x) ZVAL_ADDREF(x)
# endif
2009-03-16 05:34:02 +00:00
/* For a user friendly message about environment setup */
# if defined(PHP_WIN32)
# define PHP_OCI8_LIB_PATH_MSG "PATH"
# elif defined(__APPLE__)
# define PHP_OCI8_LIB_PATH_MSG "DYLD_LIBRARY_PATH"
2011-10-31 20:48:25 +00:00
# elif defined(_AIX)
# define PHP_OCI8_LIB_PATH_MSG "LIBPATH"
# elif defined(__hpux)
# define PHP_OCI8_LIB_PATH_MSG "SHLIB_PATH"
2009-03-16 05:34:02 +00:00
# else
# define PHP_OCI8_LIB_PATH_MSG "LD_LIBRARY_PATH"
# endif
1999-08-17 13:54:25 +00:00
/* True globals, no need for thread safety */
2005-12-01 13:39:48 +00:00
int le_connection ;
int le_pconnection ;
int le_statement ;
int le_descriptor ;
2008-01-31 01:33:30 +00:00
int le_psessionpool ;
2005-12-01 13:39:48 +00:00
int le_collection ;
zend_class_entry * oci_lob_class_entry_ptr ;
zend_class_entry * oci_coll_class_entry_ptr ;
1999-04-24 18:54:02 +00:00
# ifndef SQLT_BFILEE
1999-12-23 08:18:35 +00:00
# define SQLT_BFILEE 114
1999-04-24 18:54:02 +00:00
# endif
# ifndef SQLT_CFILEE
1999-12-23 08:18:35 +00:00
# define SQLT_CFILEE 115
1999-04-24 18:54:02 +00:00
# endif
2009-03-09 19:01:16 +00:00
# ifdef ZTS
# define PHP_OCI_INIT_MODE (OCI_DEFAULT | OCI_OBJECT | OCI_THREADED | OCI_NO_MUTEX)
# else
# define PHP_OCI_INIT_MODE (OCI_DEFAULT | OCI_OBJECT)
# endif
2013-07-24 22:33:22 +00:00
/* {{{ static protos */
2014-12-13 22:06:14 +00:00
static void php_oci_connection_list_dtor ( zend_resource * ) ;
static void php_oci_pconnection_list_dtor ( zend_resource * ) ;
static void php_oci_pconnection_list_np_dtor ( zend_resource * ) ;
static void php_oci_statement_list_dtor ( zend_resource * ) ;
static void php_oci_descriptor_list_dtor ( zend_resource * ) ;
static void php_oci_spool_list_dtor ( zend_resource * entry ) ;
static void php_oci_collection_list_dtor ( zend_resource * ) ;
2015-06-27 06:09:05 +00:00
static int php_oci_persistent_helper ( zval * zv ) ;
2014-12-13 22:06:14 +00:00
static int php_oci_connection_ping ( php_oci_connection * ) ;
static int php_oci_connection_status ( php_oci_connection * ) ;
static int php_oci_connection_close ( php_oci_connection * ) ;
static void php_oci_spool_close ( php_oci_spool * session_pool ) ;
static OCIEnv * php_oci_create_env ( ub2 charsetid ) ;
static int php_oci_create_session ( php_oci_connection * connection , php_oci_spool * session_pool , char * dbname , int dbname_len , char * username , int username_len , char * password , int password_len , char * new_password , int new_password_len , int session_mode ) ;
static int php_oci_old_create_session ( php_oci_connection * connection , char * dbname , int dbname_len , char * username , int username_len , char * password , int password_len , char * new_password , int new_password_len , int session_mode ) ;
static php_oci_spool * php_oci_get_spool ( char * username , int username_len , char * password , int password_len , char * dbname , int dbname_len , int charsetid ) ;
static php_oci_spool * php_oci_create_spool ( char * username , int username_len , char * password , int password_len , char * dbname , int dbname_len , zend_string * hash_key , int charsetid ) ;
static sword php_oci_ping_init ( php_oci_connection * connection , OCIError * errh ) ;
1999-04-21 22:49:16 +00:00
/* }}} */
/* {{{ dynamically loadable module stuff */
2020-12-14 21:42:54 +00:00
# if defined(COMPILE_DL_OCI8) || defined(COMPILE_DL_OCI8_11G) || defined(COMPILE_DL_OCI8_12C) || defined(COMPILE_DL_OCI8_19)
2000-05-02 00:30:36 +00:00
ZEND_GET_MODULE ( oci8 )
1999-04-21 22:49:16 +00:00
# endif /* COMPILE_DL */
2003-12-25 13:54:50 +00:00
/* }}} */
2020-06-10 21:37:14 +00:00
# include "oci8_arginfo.h"
1999-04-21 22:49:16 +00:00
2021-07-19 09:56:46 +00:00
static PHP_INI_MH ( OnUpdateOldCloseSemantics )
{
bool * p = ( bool * ) ZEND_INI_GET_ADDR ( ) ;
* p = zend_ini_parse_bool ( new_value ) ;
2021-07-22 14:21:46 +00:00
if ( * p ) {
2021-07-19 09:56:46 +00:00
zend_error ( E_DEPRECATED , " Directive oci8.old_oci_close_semantics is deprecated " ) ;
}
return SUCCESS ;
}
2020-07-01 13:32:55 +00:00
/* {{{ extension definition structures */
2001-04-13 14:43:39 +00:00
1999-12-17 20:55:31 +00:00
zend_module_entry oci8_module_entry = {
2001-10-11 23:33:59 +00:00
STANDARD_MODULE_HEADER ,
2008-08-06 07:54:40 +00:00
" oci8 " , /* extension name */
2020-06-10 21:37:14 +00:00
ext_functions , /* extension function list */
2008-03-12 01:26:44 +00:00
PHP_MINIT ( oci ) , /* extension-wide startup function */
PHP_MSHUTDOWN ( oci ) , /* extension-wide shutdown function */
PHP_RINIT ( oci ) , /* per-request startup function */
PHP_RSHUTDOWN ( oci ) , /* per-request shutdown function */
PHP_MINFO ( oci ) , /* information function */
2008-04-01 18:37:32 +00:00
PHP_OCI8_VERSION ,
2006-06-15 18:33:09 +00:00
PHP_MODULE_GLOBALS ( oci ) , /* globals descriptor */
2008-03-12 01:26:44 +00:00
PHP_GINIT ( oci ) , /* globals ctor */
2009-03-09 20:09:07 +00:00
PHP_GSHUTDOWN ( oci ) , /* globals dtor */
2008-03-12 01:26:44 +00:00
NULL , /* post deactivate */
2006-06-15 18:33:09 +00:00
STANDARD_MODULE_PROPERTIES_EX
1999-04-21 22:49:16 +00:00
} ;
/* }}} */
2005-12-01 13:39:48 +00:00
/* {{{ PHP_INI */
PHP_INI_BEGIN ( )
2016-08-07 00:17:06 +00:00
STD_PHP_INI_ENTRY ( " oci8.max_persistent " , " -1 " , PHP_INI_SYSTEM , OnUpdateLong , max_persistent , zend_oci_globals , oci_globals )
STD_PHP_INI_ENTRY ( " oci8.persistent_timeout " , " -1 " , PHP_INI_SYSTEM , OnUpdateLong , persistent_timeout , zend_oci_globals , oci_globals )
STD_PHP_INI_ENTRY ( " oci8.ping_interval " , " 60 " , PHP_INI_SYSTEM , OnUpdateLong , ping_interval , zend_oci_globals , oci_globals )
2008-02-26 02:21:04 +00:00
STD_PHP_INI_BOOLEAN ( " oci8.privileged_connect " , " 0 " , PHP_INI_SYSTEM , OnUpdateBool , privileged_connect , zend_oci_globals , oci_globals )
2016-08-07 00:17:06 +00:00
STD_PHP_INI_ENTRY ( " oci8.statement_cache_size " , " 20 " , PHP_INI_SYSTEM , OnUpdateLong , statement_cache_size , zend_oci_globals , oci_globals )
STD_PHP_INI_ENTRY ( " oci8.default_prefetch " , " 100 " , PHP_INI_SYSTEM , OnUpdateLong , default_prefetch , zend_oci_globals , oci_globals )
2021-07-19 09:56:46 +00:00
STD_PHP_INI_BOOLEAN ( " oci8.old_oci_close_semantics " , " 0 " , PHP_INI_SYSTEM , OnUpdateOldCloseSemantics , old_oci_close_semantics , zend_oci_globals , oci_globals )
2008-02-26 02:21:04 +00:00
STD_PHP_INI_ENTRY ( " oci8.connection_class " , " " , PHP_INI_ALL , OnUpdateString , connection_class , zend_oci_globals , oci_globals )
STD_PHP_INI_BOOLEAN ( " oci8.events " , " 0 " , PHP_INI_SYSTEM , OnUpdateBool , events , zend_oci_globals , oci_globals )
2021-11-28 01:06:25 +00:00
STD_PHP_INI_ENTRY ( " oci8.prefetch_lob_size " , " 0 " , PHP_INI_SYSTEM , OnUpdateLong , prefetch_lob_size , zend_oci_globals , oci_globals )
2005-12-01 13:39:48 +00:00
PHP_INI_END ( )
/* }}} */
2020-07-01 13:32:55 +00:00
/* {{{ startup, shutdown and info functions */
1999-04-21 22:49:16 +00:00
2008-03-12 01:26:44 +00:00
/* {{{ php_oci_init_global_handles()
2008-04-18 00:05:27 +00:00
*
* Initialize global handles only when they are needed
*/
2014-12-13 22:06:14 +00:00
static void php_oci_init_global_handles ( void )
2003-12-16 10:29:11 +00:00
{
2009-03-09 19:01:16 +00:00
sword errstatus ;
sb4 ora_error_code = 0 ;
2015-07-30 10:25:40 +00:00
text tmp_buf [ PHP_OCI_ERRBUF_LEN ] ; /* Use traditional smaller size: non-PL/SQL errors should fit and it keeps the stack smaller */
2009-03-09 19:01:16 +00:00
errstatus = OCIEnvNlsCreate ( & OCI_G ( env ) , PHP_OCI_INIT_MODE , 0 , NULL , NULL , NULL , 0 , NULL , 0 , 0 ) ;
if ( errstatus = = OCI_ERROR ) {
# ifdef HAVE_OCI_INSTANT_CLIENT
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " OCIEnvNlsCreate() failed. There is something wrong with your system - please check that " PHP_OCI8_LIB_PATH_MSG " includes the directory with Oracle Instant Client libraries " ) ;
2009-03-09 19:01:16 +00:00
# else
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " OCIEnvNlsCreate() failed. There is something wrong with your system - please check that ORACLE_HOME and " PHP_OCI8_LIB_PATH_MSG " are set and point to the right directories " ) ;
2009-03-09 19:01:16 +00:00
# endif
2010-11-10 18:59:56 +00:00
if ( OCI_G ( env )
2015-07-30 10:25:40 +00:00
& & OCIErrorGet ( OCI_G ( env ) , ( ub4 ) 1 , NULL , & ora_error_code , tmp_buf , ( ub4 ) PHP_OCI_ERRBUF_LEN , ( ub4 ) OCI_HTYPE_ENV ) = = OCI_SUCCESS
2011-06-07 23:53:02 +00:00
& & * tmp_buf ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " %s " , tmp_buf ) ;
2010-11-10 18:59:56 +00:00
}
2015-01-03 09:22:58 +00:00
2009-03-09 19:01:16 +00:00
OCI_G ( env ) = NULL ;
OCI_G ( err ) = NULL ;
return ;
2005-12-01 13:39:48 +00:00
}
2008-03-12 01:26:44 +00:00
2009-03-09 19:01:16 +00:00
errstatus = OCIHandleAlloc ( OCI_G ( env ) , ( dvoid * * ) & OCI_G ( err ) , OCI_HTYPE_ERROR , 0 , NULL ) ;
2003-12-16 10:29:11 +00:00
2021-12-12 02:32:34 +00:00
if ( errstatus ! = OCI_SUCCESS ) {
2015-07-30 10:25:40 +00:00
OCIErrorGet ( OCI_G ( env ) , ( ub4 ) 1 , NULL , & ora_error_code , tmp_buf , ( ub4 ) PHP_OCI_ERRBUF_LEN , ( ub4 ) OCI_HTYPE_ERROR ) ;
2009-03-09 19:01:16 +00:00
if ( ora_error_code ) {
2015-08-12 11:57:16 +00:00
int tmp_buf_len = ( int ) strlen ( ( char * ) tmp_buf ) ;
2015-01-03 09:22:58 +00:00
2009-03-09 19:01:16 +00:00
if ( tmp_buf_len > 0 & & tmp_buf [ tmp_buf_len - 1 ] = = ' \n ' ) {
tmp_buf [ tmp_buf_len - 1 ] = ' \0 ' ;
}
2015-01-03 09:22:58 +00:00
2009-03-09 19:01:16 +00:00
if ( errstatus = = OCI_SUCCESS_WITH_INFO ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Initialization error: OCI_SUCCESS_WITH_INFO: %s " , tmp_buf ) ;
2009-03-09 19:01:16 +00:00
} else {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Initialization error: OCI_ERROR: %s " , tmp_buf ) ;
2015-01-03 09:22:58 +00:00
2009-03-09 19:01:16 +00:00
OCIHandleFree ( ( dvoid * ) OCI_G ( env ) , OCI_HTYPE_ENV ) ;
2015-01-03 09:22:58 +00:00
2009-03-09 19:01:16 +00:00
OCI_G ( env ) = NULL ;
OCI_G ( err ) = NULL ;
}
2005-12-01 13:39:48 +00:00
}
}
2013-07-24 22:33:22 +00:00
}
/* }}} */
2003-12-16 10:29:11 +00:00
2006-06-15 18:33:09 +00:00
/* {{{ PHP_GINIT_FUNCTION
2008-04-18 00:05:27 +00:00
*
* Zerofill globals during module init
*/
2006-06-15 18:33:09 +00:00
static PHP_GINIT_FUNCTION ( oci )
2005-12-01 13:39:48 +00:00
{
memset ( oci_globals , 0 , sizeof ( zend_oci_globals ) ) ;
2003-12-16 10:29:11 +00:00
}
2005-12-01 13:39:48 +00:00
/* }}} */
2003-12-16 10:29:11 +00:00
2009-03-09 20:09:07 +00:00
/* {{{ PHP_GSHUTDOWN_FUNCTION
*
* Called for thread shutdown in ZTS , after module shutdown for non - ZTS
2021-12-12 17:37:15 +00:00
* Free global handles ( if they were initialized before )
2009-03-09 20:09:07 +00:00
*/
static PHP_GSHUTDOWN_FUNCTION ( oci )
{
2021-12-12 17:37:15 +00:00
if ( oci_globals - > err ) {
oci_globals - > in_call = 1 ;
OCIHandleFree ( ( dvoid * ) oci_globals - > err , OCI_HTYPE_ERROR ) ;
oci_globals - > in_call = 0 ;
oci_globals - > err = NULL ;
}
if ( oci_globals - > env ) {
oci_globals - > in_call = 1 ;
OCIHandleFree ( ( dvoid * ) oci_globals - > env , OCI_HTYPE_ENV ) ;
oci_globals - > in_call = 0 ;
oci_globals - > env = NULL ;
}
2009-03-09 20:09:07 +00:00
}
/* }}} */
1999-08-17 13:54:25 +00:00
PHP_MINIT_FUNCTION ( oci )
{
2005-12-01 13:39:48 +00:00
REGISTER_INI_ENTRIES ( ) ;
le_statement = zend_register_list_destructors_ex ( php_oci_statement_list_dtor , NULL , " oci8 statement " , module_number ) ;
le_connection = zend_register_list_destructors_ex ( php_oci_connection_list_dtor , NULL , " oci8 connection " , module_number ) ;
2008-03-12 01:26:44 +00:00
le_pconnection = zend_register_list_destructors_ex ( php_oci_pconnection_list_np_dtor , php_oci_pconnection_list_dtor , " oci8 persistent connection " , module_number ) ;
2008-01-31 01:33:30 +00:00
le_psessionpool = zend_register_list_destructors_ex ( NULL , php_oci_spool_list_dtor , " oci8 persistent session pool " , module_number ) ;
2005-12-01 13:39:48 +00:00
le_descriptor = zend_register_list_destructors_ex ( php_oci_descriptor_list_dtor , NULL , " oci8 descriptor " , module_number ) ;
le_collection = zend_register_list_destructors_ex ( php_oci_collection_list_dtor , NULL , " oci8 collection " , module_number ) ;
1999-08-17 13:54:25 +00:00
2021-02-14 11:00:03 +00:00
oci_lob_class_entry_ptr = register_class_OCILob ( ) ;
oci_coll_class_entry_ptr = register_class_OCICollection ( ) ;
1999-04-21 22:49:16 +00:00
2000-10-29 09:14:55 +00:00
/* thies@thieso.net 990203 i do not think that we will need all of them - just in here for completeness for now! */
2014-08-25 17:24:55 +00:00
REGISTER_LONG_CONSTANT ( " OCI_DEFAULT " , OCI_DEFAULT , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_SYSOPER " , OCI_SYSOPER , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_SYSDBA " , OCI_SYSDBA , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_CRED_EXT " , PHP_OCI_CRED_EXT , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_DESCRIBE_ONLY " , OCI_DESCRIBE_ONLY , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_COMMIT_ON_SUCCESS " , OCI_COMMIT_ON_SUCCESS , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_NO_AUTO_COMMIT " , OCI_DEFAULT , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_EXACT_FETCH " , OCI_EXACT_FETCH , CONST_CS | CONST_PERSISTENT ) ;
1999-04-21 22:49:16 +00:00
2003-12-15 13:53:01 +00:00
/* for $LOB->seek() */
2014-08-25 17:24:55 +00:00
REGISTER_LONG_CONSTANT ( " OCI_SEEK_SET " , PHP_OCI_SEEK_SET , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_SEEK_CUR " , PHP_OCI_SEEK_CUR , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_SEEK_END " , PHP_OCI_SEEK_END , CONST_CS | CONST_PERSISTENT ) ;
2003-12-15 13:53:01 +00:00
/* for $LOB->flush() */
2014-08-25 17:24:55 +00:00
REGISTER_LONG_CONSTANT ( " OCI_LOB_BUFFER_FREE " , OCI_LOB_BUFFER_FREE , CONST_CS | CONST_PERSISTENT ) ;
2008-03-12 01:26:44 +00:00
/* for OCIBindByName (real "oci" names + short "php" names */
2014-08-25 17:24:55 +00:00
REGISTER_LONG_CONSTANT ( " SQLT_BFILEE " , SQLT_BFILEE , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " SQLT_CFILEE " , SQLT_CFILEE , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " SQLT_CLOB " , SQLT_CLOB , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " SQLT_BLOB " , SQLT_BLOB , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " SQLT_RDD " , SQLT_RDD , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " SQLT_INT " , SQLT_INT , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " SQLT_NUM " , SQLT_NUM , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " SQLT_RSET " , SQLT_RSET , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " SQLT_AFC " , SQLT_AFC , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " SQLT_CHR " , SQLT_CHR , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " SQLT_VCS " , SQLT_VCS , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " SQLT_AVC " , SQLT_AVC , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " SQLT_STR " , SQLT_STR , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " SQLT_LVC " , SQLT_LVC , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " SQLT_FLT " , SQLT_FLT , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " SQLT_UIN " , SQLT_UIN , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " SQLT_LNG " , SQLT_LNG , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " SQLT_LBI " , SQLT_LBI , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " SQLT_BIN " , SQLT_BIN , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " SQLT_ODT " , SQLT_ODT , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " SQLT_BDOUBLE " , SQLT_BDOUBLE , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " SQLT_BFLOAT " , SQLT_BFLOAT , CONST_CS | CONST_PERSISTENT ) ;
2021-12-12 02:32:34 +00:00
# if OCI_MAJOR_VERSION >= 12
2014-08-25 17:24:55 +00:00
REGISTER_LONG_CONSTANT ( " SQLT_BOL " , SQLT_BOL , CONST_CS | CONST_PERSISTENT ) ;
2014-02-10 23:00:42 +00:00
# endif
1999-04-21 22:49:16 +00:00
2014-08-25 17:24:55 +00:00
REGISTER_LONG_CONSTANT ( " OCI_B_NTY " , SQLT_NTY , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " SQLT_NTY " , SQLT_NTY , CONST_CS | CONST_PERSISTENT ) ;
2005-12-01 13:39:48 +00:00
REGISTER_STRING_CONSTANT ( " OCI_SYSDATE " , " SYSDATE " , CONST_CS | CONST_PERSISTENT ) ;
2001-04-13 14:43:39 +00:00
2014-08-25 17:24:55 +00:00
REGISTER_LONG_CONSTANT ( " OCI_B_BFILE " , SQLT_BFILEE , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_B_CFILEE " , SQLT_CFILEE , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_B_CLOB " , SQLT_CLOB , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_B_BLOB " , SQLT_BLOB , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_B_ROWID " , SQLT_RDD , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_B_CURSOR " , SQLT_RSET , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_B_BIN " , SQLT_BIN , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_B_INT " , SQLT_INT , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_B_NUM " , SQLT_NUM , CONST_CS | CONST_PERSISTENT ) ;
2021-12-12 02:32:34 +00:00
# if OCI_MAJOR_VERSION >= 12
2014-08-25 17:24:55 +00:00
REGISTER_LONG_CONSTANT ( " OCI_B_BOL " , SQLT_BOL , CONST_CS | CONST_PERSISTENT ) ;
2014-02-10 23:00:42 +00:00
# endif
1999-04-21 22:49:16 +00:00
2002-01-17 18:40:59 +00:00
/* for OCIFetchStatement */
2014-08-25 17:24:55 +00:00
REGISTER_LONG_CONSTANT ( " OCI_FETCHSTATEMENT_BY_COLUMN " , PHP_OCI_FETCHSTATEMENT_BY_COLUMN , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_FETCHSTATEMENT_BY_ROW " , PHP_OCI_FETCHSTATEMENT_BY_ROW , CONST_CS | CONST_PERSISTENT ) ;
2002-01-17 18:40:59 +00:00
2008-06-05 23:43:10 +00:00
/* for OCIFetchInto & OCIResult */
2014-08-25 17:24:55 +00:00
REGISTER_LONG_CONSTANT ( " OCI_ASSOC " , PHP_OCI_ASSOC , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_NUM " , PHP_OCI_NUM , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_BOTH " , PHP_OCI_BOTH , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_RETURN_NULLS " , PHP_OCI_RETURN_NULLS , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_RETURN_LOBS " , PHP_OCI_RETURN_LOBS , CONST_CS | CONST_PERSISTENT ) ;
1999-04-21 22:49:16 +00:00
2008-03-12 01:26:44 +00:00
/* for OCINewDescriptor (real "oci" names + short "php" names */
2014-08-25 17:24:55 +00:00
REGISTER_LONG_CONSTANT ( " OCI_DTYPE_FILE " , OCI_DTYPE_FILE , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_DTYPE_LOB " , OCI_DTYPE_LOB , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_DTYPE_ROWID " , OCI_DTYPE_ROWID , CONST_CS | CONST_PERSISTENT ) ;
1999-04-21 22:49:16 +00:00
2014-08-25 17:24:55 +00:00
REGISTER_LONG_CONSTANT ( " OCI_D_FILE " , OCI_DTYPE_FILE , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_D_LOB " , OCI_DTYPE_LOB , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_D_ROWID " , OCI_DTYPE_ROWID , CONST_CS | CONST_PERSISTENT ) ;
1999-04-21 22:49:16 +00:00
2003-07-22 10:38:34 +00:00
/* for OCIWriteTemporaryLob */
2014-08-25 17:24:55 +00:00
REGISTER_LONG_CONSTANT ( " OCI_TEMP_CLOB " , OCI_TEMP_CLOB , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_TEMP_BLOB " , OCI_TEMP_BLOB , CONST_CS | CONST_PERSISTENT ) ;
2003-07-22 10:38:34 +00:00
2017-04-07 18:40:40 +00:00
/* for Transparent Application Failover */
REGISTER_LONG_CONSTANT ( " OCI_FO_END " , OCI_FO_END , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_FO_ABORT " , OCI_FO_ABORT , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_FO_REAUTH " , OCI_FO_REAUTH , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_FO_BEGIN " , OCI_FO_BEGIN , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_FO_ERROR " , OCI_FO_ERROR , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_FO_NONE " , OCI_FO_NONE , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_FO_SESSION " , OCI_FO_SESSION , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_FO_SELECT " , OCI_FO_SELECT , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_FO_TXNAL " , OCI_FO_TXNAL , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " OCI_FO_RETRY " , OCI_FO_RETRY , CONST_CS | CONST_PERSISTENT ) ;
2022-04-12 12:47:46 +00:00
register_oci8_symbols ( module_number ) ;
1999-04-21 22:49:16 +00:00
return SUCCESS ;
}
1999-08-17 13:54:25 +00:00
PHP_RINIT_FUNCTION ( oci )
1999-04-21 22:49:16 +00:00
{
2005-12-01 13:39:48 +00:00
OCI_G ( num_links ) = OCI_G ( num_persistent ) ;
OCI_G ( errcode ) = 0 ;
2009-10-06 22:36:32 +00:00
OCI_G ( edition ) = NULL ;
1999-04-21 22:49:16 +00:00
2002-11-15 17:59:19 +00:00
return SUCCESS ;
1999-04-21 22:49:16 +00:00
}
1999-08-17 13:54:25 +00:00
PHP_MSHUTDOWN_FUNCTION ( oci )
1999-04-21 22:49:16 +00:00
{
2009-03-09 20:09:07 +00:00
OCI_G ( shutdown ) = 1 ;
UNREGISTER_INI_ENTRIES ( ) ;
1999-04-24 18:54:02 +00:00
2000-01-16 13:30:57 +00:00
return SUCCESS ;
1999-06-09 10:40:08 +00:00
}
1999-08-17 13:54:25 +00:00
PHP_RSHUTDOWN_FUNCTION ( oci )
1999-04-21 22:49:16 +00:00
{
2008-04-18 00:05:27 +00:00
/* Check persistent connections and do the necessary actions if needed. If persistent_helper is
* unable to process a pconnection because of a refcount , the processing would happen from
* np - destructor which is called when refcount goes to zero - php_oci_pconnection_list_np_dtor
*/
2015-06-27 06:09:05 +00:00
zend_hash_apply ( & EG ( persistent_list ) , php_oci_persistent_helper ) ;
2000-01-16 13:30:57 +00:00
2009-10-06 22:36:32 +00:00
if ( OCI_G ( edition ) ) {
efree ( OCI_G ( edition ) ) ;
}
2002-11-15 17:59:19 +00:00
return SUCCESS ;
1999-04-21 22:49:16 +00:00
}
1999-08-17 13:54:25 +00:00
PHP_MINFO_FUNCTION ( oci )
1999-04-21 22:49:16 +00:00
{
2003-12-16 10:29:11 +00:00
char buf [ 32 ] ;
2015-07-30 10:25:40 +00:00
char ver [ 256 ] ;
2000-04-06 21:07:44 +00:00
php_info_print_table_start ( ) ;
php_info_print_table_row ( 2 , " OCI8 Support " , " enabled " ) ;
2013-08-31 00:37:44 +00:00
# if defined(HAVE_OCI8_DTRACE)
php_info_print_table_row ( 2 , " OCI8 DTrace Support " , " enabled " ) ;
# else
php_info_print_table_row ( 2 , " OCI8 DTrace Support " , " disabled " ) ;
# endif
2013-07-24 22:33:22 +00:00
php_info_print_table_row ( 2 , " OCI8 Version " , PHP_OCI8_VERSION ) ;
2003-12-16 10:29:11 +00:00
2015-07-30 10:25:40 +00:00
php_oci_client_get_version ( ver , sizeof ( ver ) ) ;
2011-06-10 17:38:07 +00:00
php_info_print_table_row ( 2 , " Oracle Run-time Client Library Version " , ver ) ;
2010-06-25 21:09:13 +00:00
snprintf ( buf , sizeof ( buf ) , " %d.%d " , OCI_MAJOR_VERSION , OCI_MINOR_VERSION ) ;
# if defined(HAVE_OCI_INSTANT_CLIENT)
2013-07-24 22:33:22 +00:00
php_info_print_table_row ( 2 , " Oracle Compile-time Instant Client Version " , buf ) ;
2010-06-25 21:09:13 +00:00
# else
2013-07-24 22:33:22 +00:00
php_info_print_table_row ( 2 , " Oracle Compile-time Version " , buf ) ;
2008-04-18 00:05:27 +00:00
# endif
2010-06-25 21:09:13 +00:00
# if !defined(PHP_WIN32) && !defined(HAVE_OCI_INSTANT_CLIENT)
# if defined(PHP_OCI8_DEF_DIR)
2009-03-09 17:42:22 +00:00
php_info_print_table_row ( 2 , " Compile-time ORACLE_HOME " , PHP_OCI8_DEF_DIR ) ;
2008-04-18 00:05:27 +00:00
# endif
2010-06-25 21:09:13 +00:00
# if defined(PHP_OCI8_DEF_SHARED_LIBADD)
2009-03-09 17:42:22 +00:00
php_info_print_table_row ( 2 , " Libraries Used " , PHP_OCI8_DEF_SHARED_LIBADD ) ;
2008-04-01 18:37:32 +00:00
# endif
1999-04-21 22:49:16 +00:00
# endif
2003-12-16 15:58:10 +00:00
2013-08-31 00:37:44 +00:00
2004-01-02 15:32:09 +00:00
php_info_print_table_end ( ) ;
2013-07-24 22:33:22 +00:00
2005-12-01 13:39:48 +00:00
DISPLAY_INI_ENTRIES ( ) ;
2013-07-24 22:33:22 +00:00
php_info_print_table_start ( ) ;
php_info_print_table_header ( 2 , " Statistics " , " " ) ;
2016-08-07 00:17:06 +00:00
snprintf ( buf , sizeof ( buf ) , ZEND_LONG_FMT , OCI_G ( num_persistent ) ) ;
2013-07-24 22:33:22 +00:00
php_info_print_table_row ( 2 , " Active Persistent Connections " , buf ) ;
2016-08-07 00:17:06 +00:00
snprintf ( buf , sizeof ( buf ) , ZEND_LONG_FMT , OCI_G ( num_links ) ) ;
2013-07-24 22:33:22 +00:00
php_info_print_table_row ( 2 , " Active Connections " , buf ) ;
php_info_print_table_end ( ) ;
1999-04-21 22:49:16 +00:00
}
/* }}} */
2013-07-24 22:33:22 +00:00
/* {{{ list destructors */
1999-09-13 11:13:53 +00:00
2005-12-01 13:39:48 +00:00
/* {{{ php_oci_connection_list_dtor()
2008-04-18 00:05:27 +00:00
*
* Non - persistent connection destructor
*/
2014-12-13 22:06:14 +00:00
static void php_oci_connection_list_dtor ( zend_resource * entry )
2005-12-01 13:39:48 +00:00
{
php_oci_connection * connection = ( php_oci_connection * ) entry - > ptr ;
2008-03-12 01:26:44 +00:00
if ( connection ) {
2014-12-13 22:06:14 +00:00
php_oci_connection_close ( connection ) ;
2008-03-12 01:26:44 +00:00
OCI_G ( num_links ) - - ;
}
2013-07-24 22:33:22 +00:00
}
/* }}} */
1999-04-21 22:49:16 +00:00
2005-12-01 13:39:48 +00:00
/* {{{ php_oci_pconnection_list_dtor()
2008-04-18 00:05:27 +00:00
*
* Persistent connection destructor
*/
2014-12-13 22:06:14 +00:00
static void php_oci_pconnection_list_dtor ( zend_resource * entry )
2005-12-01 13:39:48 +00:00
{
php_oci_connection * connection = ( php_oci_connection * ) entry - > ptr ;
2008-03-12 01:26:44 +00:00
if ( connection ) {
2014-12-13 22:06:14 +00:00
php_oci_connection_close ( connection ) ;
2008-03-12 01:26:44 +00:00
OCI_G ( num_persistent ) - - ;
2008-08-28 06:33:24 +00:00
OCI_G ( num_links ) - - ;
2008-03-12 01:26:44 +00:00
}
2013-07-24 22:33:22 +00:00
}
/* }}} */
2008-03-12 01:26:44 +00:00
/* {{{ php_oci_pconnection_list_np_dtor()
2008-04-18 00:05:27 +00:00
*
* Non - Persistent destructor for persistent connection - This gets invoked when
* the refcount of this goes to zero in the regular list
*/
2014-12-13 22:06:14 +00:00
static void php_oci_pconnection_list_np_dtor ( zend_resource * entry )
2008-03-12 01:26:44 +00:00
{
php_oci_connection * connection = ( php_oci_connection * ) entry - > ptr ;
2014-05-21 23:43:44 +00:00
zval * zvp ;
zend_resource * le ;
2008-03-12 01:26:44 +00:00
2008-04-18 00:05:27 +00:00
/*
* We cannot get connection as NULL or as a stub in this function . This is the function that
* turns a pconnection to a stub
*
* If oci_password_change ( ) changed the password of a persistent connection , close the
* connection and remove it from the persistent connection cache . This means subsequent scripts
* will be prevented from being able to present the old ( now invalid ) password to a usable
* connection to the database ; they must use the new password .
*
* Check for conditions that warrant removal of the hash entry
*/
2008-03-22 01:27:50 +00:00
2008-04-18 00:05:27 +00:00
if ( ! connection - > is_open | |
connection - > passwd_changed | |
( PG ( connection_status ) & PHP_CONNECTION_TIMEOUT ) | |
OCI_G ( in_call ) ) {
/* Remove the hash entry if present */
2015-07-13 01:50:00 +00:00
if ( connection - > hash_key ) {
zvp = zend_hash_find ( & EG ( persistent_list ) , connection - > hash_key ) ;
2015-11-15 21:15:22 +00:00
le = zvp ? Z_RES_P ( zvp ) : NULL ;
2015-07-13 01:50:00 +00:00
if ( le ! = NULL & & le - > type = = le_pconnection & & le - > ptr = = connection ) {
zend_hash_del ( & EG ( persistent_list ) , connection - > hash_key ) ;
}
else {
php_oci_connection_close ( connection ) ;
OCI_G ( num_persistent ) - - ;
}
2008-04-18 00:05:27 +00:00
}
2008-03-22 01:27:50 +00:00
2013-08-31 00:37:44 +00:00
# ifdef HAVE_OCI8_DTRACE
2013-07-24 22:33:22 +00:00
if ( DTRACE_OCI8_CONNECT_P_DTOR_CLOSE_ENABLED ( ) ) {
DTRACE_OCI8_CONNECT_P_DTOR_CLOSE ( connection ) ;
2008-03-22 01:27:50 +00:00
}
2013-08-31 00:37:44 +00:00
# endif /* HAVE_OCI8_DTRACE */
2013-07-24 22:33:22 +00:00
} else {
2008-04-18 00:05:27 +00:00
/*
* Release the connection to underlying pool . We do this unconditionally so that
* out - of - scope pconnects are now consistent with oci_close and out - of - scope new connect
* semantics . With the PECL OCI 1.3 . x extensions , we release pconnections when oci_close
* takes the refcount to zero .
*
2014-11-19 19:59:31 +00:00
* If oci_old_close_semantics is set , we artificially bump up the refcount and decremented
2008-04-18 00:05:27 +00:00
* only at request shutdown .
*/
2014-12-13 22:06:14 +00:00
php_oci_connection_release ( connection ) ;
2008-03-22 01:27:50 +00:00
2013-08-31 00:37:44 +00:00
# ifdef HAVE_OCI8_DTRACE
2013-07-24 22:33:22 +00:00
if ( DTRACE_OCI8_CONNECT_P_DTOR_RELEASE_ENABLED ( ) ) {
DTRACE_OCI8_CONNECT_P_DTOR_RELEASE ( connection ) ;
2008-03-22 01:27:50 +00:00
}
2013-08-31 00:37:44 +00:00
# endif /* HAVE_OCI8_DTRACE */
2008-03-12 01:26:44 +00:00
}
2013-07-24 22:33:22 +00:00
}
/* }}} */
2004-01-02 15:32:09 +00:00
2005-12-01 13:39:48 +00:00
/* {{{ php_oci_statement_list_dtor()
2008-04-18 00:05:27 +00:00
*
* Statement destructor
*/
2014-12-13 22:06:14 +00:00
static void php_oci_statement_list_dtor ( zend_resource * entry )
2003-12-25 13:54:50 +00:00
{
2005-12-01 13:39:48 +00:00
php_oci_statement * statement = ( php_oci_statement * ) entry - > ptr ;
2014-12-13 22:06:14 +00:00
php_oci_statement_free ( statement ) ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
1999-04-21 22:49:16 +00:00
2005-12-01 13:39:48 +00:00
/* {{{ php_oci_descriptor_list_dtor()
2008-04-18 00:05:27 +00:00
*
* Descriptor destructor
*/
2014-12-13 22:06:14 +00:00
static void php_oci_descriptor_list_dtor ( zend_resource * entry )
2000-01-16 13:30:57 +00:00
{
2005-12-01 13:39:48 +00:00
php_oci_descriptor * descriptor = ( php_oci_descriptor * ) entry - > ptr ;
2014-12-13 22:06:14 +00:00
php_oci_lob_free ( descriptor ) ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2000-01-16 13:30:57 +00:00
2005-12-01 13:39:48 +00:00
/* {{{ php_oci_collection_list_dtor()
2008-04-18 00:05:27 +00:00
*
* Collection destructor
*/
2014-12-13 22:06:14 +00:00
static void php_oci_collection_list_dtor ( zend_resource * entry )
2005-12-01 13:39:48 +00:00
{
php_oci_collection * collection = ( php_oci_collection * ) entry - > ptr ;
2014-12-13 22:06:14 +00:00
php_oci_collection_close ( collection ) ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2000-01-16 13:30:57 +00:00
/* }}} */
2013-07-24 22:33:22 +00:00
/* {{{ Hash Destructors */
2000-01-16 13:30:57 +00:00
2005-12-01 13:39:48 +00:00
/* {{{ php_oci_define_hash_dtor()
2008-04-18 00:05:27 +00:00
*
* Define hash destructor
*/
2015-06-27 06:09:05 +00:00
void php_oci_define_hash_dtor ( zval * data )
2005-12-01 13:39:48 +00:00
{
2015-06-27 06:09:05 +00:00
php_oci_define * define = ( php_oci_define * ) Z_PTR_P ( data ) ;
2000-01-16 13:30:57 +00:00
2005-12-01 13:39:48 +00:00
if ( define - > name ) {
efree ( define - > name ) ;
define - > name = NULL ;
}
2015-07-13 01:50:00 +00:00
2017-09-20 13:46:04 +00:00
zval_ptr_dtor ( & define - > val ) ;
2021-06-29 08:04:10 +00:00
efree ( define ) ;
2000-01-16 13:30:57 +00:00
}
2000-02-07 10:31:43 +00:00
/* }}} */
2005-12-01 13:39:48 +00:00
/* {{{ php_oci_bind_hash_dtor()
2008-04-18 00:05:27 +00:00
*
* Bind hash destructor
*/
2015-06-27 06:09:05 +00:00
void php_oci_bind_hash_dtor ( zval * data )
2000-02-07 10:31:43 +00:00
{
2015-06-27 06:09:05 +00:00
php_oci_bind * bind = ( php_oci_bind * ) Z_PTR_P ( data ) ;
2000-02-07 10:31:43 +00:00
2017-09-20 13:46:04 +00:00
if ( ! Z_ISUNDEF ( bind - > val ) ) {
zval_ptr_dtor ( & bind - > val ) ;
ZVAL_UNDEF ( & bind - > val ) ;
2016-10-17 01:40:14 +00:00
}
2005-12-01 13:39:48 +00:00
if ( bind - > array . elements ) {
efree ( bind - > array . elements ) ;
2015-07-30 10:25:40 +00:00
bind - > array . elements = NULL ;
2000-02-07 10:31:43 +00:00
}
2007-01-11 11:27:52 +00:00
2006-07-31 10:30:23 +00:00
if ( bind - > array . element_lengths ) {
2005-12-01 13:39:48 +00:00
efree ( bind - > array . element_lengths ) ;
2015-07-30 10:25:40 +00:00
bind - > array . element_lengths = NULL ;
2005-12-01 13:39:48 +00:00
}
2007-01-11 11:27:52 +00:00
2005-12-01 13:39:48 +00:00
if ( bind - > array . indicators ) {
efree ( bind - > array . indicators ) ;
2015-07-30 10:25:40 +00:00
bind - > array . indicators = NULL ;
2007-01-11 11:27:52 +00:00
}
2015-07-13 01:50:00 +00:00
2015-06-30 03:54:40 +00:00
efree ( bind ) ;
2000-02-07 10:31:43 +00:00
}
2000-01-16 13:30:57 +00:00
/* }}} */
2005-12-01 13:39:48 +00:00
/* {{{ php_oci_column_hash_dtor()
2008-04-18 00:05:27 +00:00
*
* Column hash destructor
*/
2015-06-27 06:09:05 +00:00
void php_oci_column_hash_dtor ( zval * data )
2006-01-05 13:42:35 +00:00
{
2015-06-27 06:09:05 +00:00
php_oci_out_column * column = ( php_oci_out_column * ) Z_PTR_P ( data ) ;
1999-04-21 22:49:16 +00:00
2015-06-27 06:09:05 +00:00
if ( column - > stmtid ) {
2014-05-21 23:43:44 +00:00
zend_list_close ( column - > stmtid ) ;
2015-06-27 06:09:05 +00:00
}
2000-01-16 13:30:57 +00:00
2015-07-13 01:50:00 +00:00
if ( column - > descid ) {
2015-07-30 10:25:40 +00:00
if ( GC_REFCOUNT ( column - > descid ) = = 1 )
zend_list_close ( column - > descid ) ;
2018-09-24 10:05:54 +00:00
else {
GC_DELREF ( column - > descid ) ;
}
2015-06-27 06:09:05 +00:00
}
1999-04-21 22:49:16 +00:00
2005-12-01 13:39:48 +00:00
if ( column - > data ) {
efree ( column - > data ) ;
}
1999-09-29 14:20:27 +00:00
1999-04-21 22:49:16 +00:00
if ( column - > name ) {
efree ( column - > name ) ;
}
2015-06-30 03:54:40 +00:00
efree ( column ) ;
1999-04-21 22:49:16 +00:00
}
/* }}} */
2004-01-02 15:32:09 +00:00
2005-12-01 13:39:48 +00:00
/* {{{ php_oci_descriptor_flush_hash_dtor()
2008-04-18 00:05:27 +00:00
*
* Flush descriptors on commit
*/
2015-06-27 06:09:05 +00:00
void php_oci_descriptor_flush_hash_dtor ( zval * data )
1999-04-21 22:49:16 +00:00
{
2015-06-27 06:09:05 +00:00
php_oci_descriptor * descriptor = ( php_oci_descriptor * ) Z_PTR_P ( data ) ;
2008-03-12 01:26:44 +00:00
2006-01-05 13:42:35 +00:00
if ( descriptor & & descriptor - > buffering = = PHP_OCI_LOB_BUFFER_USED & & ( descriptor - > type = = OCI_DTYPE_LOB | | descriptor - > type = = OCI_DTYPE_FILE ) ) {
2014-12-13 22:06:14 +00:00
php_oci_lob_flush ( descriptor , OCI_LOB_BUFFER_FREE ) ;
2005-12-01 13:39:48 +00:00
descriptor - > buffering = PHP_OCI_LOB_BUFFER_ENABLED ;
2003-12-16 10:29:11 +00:00
}
2006-01-05 13:42:35 +00:00
data = NULL ;
}
/* }}} */
2010-01-06 18:58:16 +00:00
/* }}} */
/* {{{ php_oci_connection_descriptors_free()
2008-04-18 00:05:27 +00:00
*
2010-01-06 18:58:16 +00:00
* Free descriptors for a connection
2008-04-18 00:05:27 +00:00
*/
2014-12-13 22:06:14 +00:00
void php_oci_connection_descriptors_free ( php_oci_connection * connection )
2006-01-05 13:42:35 +00:00
{
2010-01-06 18:58:16 +00:00
zend_hash_destroy ( connection - > descriptors ) ;
efree ( connection - > descriptors ) ;
connection - > descriptors = NULL ;
connection - > descriptor_count = 0 ;
2000-02-01 14:39:59 +00:00
}
1999-04-21 22:49:16 +00:00
/* }}} */
2001-02-12 14:36:28 +00:00
2005-12-01 13:39:48 +00:00
/* {{{ php_oci_error()
2008-04-18 00:05:27 +00:00
*
* Fetch & print out error message if we get an error
2010-03-24 22:08:55 +00:00
* Returns an Oracle error number
2008-04-18 00:05:27 +00:00
*/
2014-12-13 22:06:14 +00:00
sb4 php_oci_error ( OCIError * err_p , sword errstatus )
1999-04-21 22:49:16 +00:00
{
2015-07-30 10:25:40 +00:00
text errbuf [ PHP_OCI_ERRBUF_LEN ] ;
2013-09-06 01:18:29 +00:00
sb4 errcode = 0 ; /* Oracle error number */
1999-04-21 22:49:16 +00:00
2013-09-06 01:18:29 +00:00
switch ( errstatus ) {
2004-01-02 15:32:09 +00:00
case OCI_SUCCESS :
break ;
case OCI_SUCCESS_WITH_INFO :
2015-07-30 10:25:40 +00:00
errcode = php_oci_fetch_errmsg ( err_p , errbuf , sizeof ( errbuf ) ) ;
if ( errcode ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " OCI_SUCCESS_WITH_INFO: %s " , errbuf ) ;
2006-08-15 12:27:24 +00:00
} else {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " OCI_SUCCESS_WITH_INFO: failed to fetch error message " ) ;
2006-08-15 12:27:24 +00:00
}
2004-01-02 15:32:09 +00:00
break ;
case OCI_NEED_DATA :
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " OCI_NEED_DATA " ) ;
2004-01-02 15:32:09 +00:00
break ;
case OCI_NO_DATA :
2015-07-30 10:25:40 +00:00
errcode = php_oci_fetch_errmsg ( err_p , errbuf , sizeof ( errbuf ) ) ;
if ( errcode ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " %s " , errbuf ) ;
2009-10-01 05:51:11 +00:00
} else {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " OCI_NO_DATA: failed to fetch error message " ) ;
2009-10-01 05:51:11 +00:00
}
2004-01-02 15:32:09 +00:00
break ;
2008-02-16 01:20:22 +00:00
case OCI_ERROR :
2015-07-30 10:25:40 +00:00
errcode = php_oci_fetch_errmsg ( err_p , errbuf , sizeof ( errbuf ) ) ;
if ( errcode ) {
2018-09-24 10:05:54 +00:00
php_error_docref ( NULL , E_WARNING , " %s " , errbuf ) ;
2006-08-15 12:27:24 +00:00
} else {
2020-01-15 10:27:29 +00:00
php_error_docref ( NULL , E_WARNING , " Failed to fetch error message " ) ;
2006-08-15 12:27:24 +00:00
}
2001-08-15 16:00:56 +00:00
break ;
2004-01-02 15:32:09 +00:00
case OCI_INVALID_HANDLE :
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " OCI_INVALID_HANDLE " ) ;
2004-01-02 15:32:09 +00:00
break ;
case OCI_STILL_EXECUTING :
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " OCI_STILL_EXECUTING " ) ;
2004-01-02 15:32:09 +00:00
break ;
case OCI_CONTINUE :
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " OCI_CONTINUE " ) ;
2004-01-02 15:32:09 +00:00
break ;
default :
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Unknown OCI error code: %d " , errstatus ) ;
2004-01-02 15:32:09 +00:00
break ;
2002-11-15 17:59:19 +00:00
}
2013-07-24 22:33:22 +00:00
2013-08-31 00:37:44 +00:00
# ifdef HAVE_OCI8_DTRACE
2013-07-24 22:33:22 +00:00
if ( DTRACE_OCI8_ERROR_ENABLED ( ) ) {
2013-09-06 01:18:29 +00:00
DTRACE_OCI8_ERROR ( ( int ) errstatus , ( long ) errcode ) ;
2013-07-24 22:33:22 +00:00
}
2013-08-31 00:37:44 +00:00
# endif /* HAVE_OCI8_DTRACE */
2013-07-24 22:33:22 +00:00
2002-11-15 17:59:19 +00:00
return errcode ;
1999-04-21 22:49:16 +00:00
}
/* }}} */
2005-12-01 13:39:48 +00:00
/* {{{ php_oci_fetch_errmsg()
2008-04-18 00:05:27 +00:00
*
* Fetch error message into the buffer from the error handle provided
*/
2015-07-30 10:25:40 +00:00
sb4 php_oci_fetch_errmsg ( OCIError * error_handle , text * error_buf , size_t error_buf_size )
1999-04-21 22:49:16 +00:00
{
2005-12-01 13:39:48 +00:00
sb4 error_code = 0 ;
2008-03-12 01:26:44 +00:00
2015-07-30 10:25:40 +00:00
PHP_OCI_CALL ( OCIErrorGet , ( error_handle , ( ub4 ) 1 , NULL , & error_code , error_buf , ( ub4 ) error_buf_size , ( ub4 ) OCI_HTYPE_ERROR ) ) ;
2005-12-01 13:39:48 +00:00
if ( error_code ) {
2015-08-12 11:57:16 +00:00
int err_buf_len = ( int ) strlen ( ( char * ) error_buf ) ;
2008-03-12 01:26:44 +00:00
2015-07-30 10:25:40 +00:00
if ( err_buf_len & & error_buf [ err_buf_len - 1 ] = = ' \n ' ) {
error_buf [ err_buf_len - 1 ] = ' \0 ' ;
2005-12-01 13:39:48 +00:00
}
1999-09-30 08:41:45 +00:00
}
2005-12-01 13:39:48 +00:00
return error_code ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
1999-09-30 08:41:45 +00:00
2005-12-01 13:39:48 +00:00
/* {{{ php_oci_fetch_sqltext_offset()
2008-04-18 00:05:27 +00:00
*
* Compute offset in the SQL statement
*/
2014-12-13 22:06:14 +00:00
int php_oci_fetch_sqltext_offset ( php_oci_statement * statement , text * * sqltext , ub2 * error_offset )
1999-04-21 22:49:16 +00:00
{
2010-03-24 22:08:55 +00:00
sword errstatus ;
1999-04-21 22:49:16 +00:00
2010-05-03 19:29:05 +00:00
* sqltext = NULL ;
* error_offset = 0 ;
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( errstatus , OCIAttrGet , ( ( dvoid * ) statement - > stmt , OCI_HTYPE_STMT , ( dvoid * ) sqltext , ( ub4 * ) 0 , OCI_ATTR_STATEMENT , statement - > err ) ) ;
2008-03-12 01:26:44 +00:00
2010-03-24 22:08:55 +00:00
if ( errstatus ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
statement - > errcode = php_oci_error ( statement - > err , errstatus ) ;
2008-03-22 01:27:50 +00:00
PHP_OCI_HANDLE_ERROR ( statement - > connection , statement - > errcode ) ;
2005-12-01 13:39:48 +00:00
return 1 ;
1999-04-24 18:54:02 +00:00
}
2000-01-16 13:30:57 +00:00
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( errstatus , OCIAttrGet , ( ( dvoid * ) statement - > stmt , OCI_HTYPE_STMT , ( ub2 * ) error_offset , ( ub4 * ) 0 , OCI_ATTR_PARSE_ERROR_OFFSET , statement - > err ) ) ;
2008-03-12 01:26:44 +00:00
2010-03-24 22:08:55 +00:00
if ( errstatus ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
statement - > errcode = php_oci_error ( statement - > err , errstatus ) ;
2008-03-22 01:27:50 +00:00
PHP_OCI_HANDLE_ERROR ( statement - > connection , statement - > errcode ) ;
2005-12-01 13:39:48 +00:00
return 1 ;
2000-01-16 13:30:57 +00:00
}
2005-12-01 13:39:48 +00:00
return 0 ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
1999-04-21 22:49:16 +00:00
2008-02-16 01:20:22 +00:00
/* {{{ php_oci_do_connect()
2008-04-18 00:05:27 +00:00
*
* Connect wrapper
*/
2005-12-01 13:39:48 +00:00
void php_oci_do_connect ( INTERNAL_FUNCTION_PARAMETERS , int persistent , int exclusive )
1999-04-21 22:49:16 +00:00
{
2005-12-01 13:39:48 +00:00
php_oci_connection * connection ;
char * username , * password ;
char * dbname = NULL , * charset = NULL ;
2014-09-09 11:12:26 +00:00
size_t username_len = 0 , password_len = 0 ;
size_t dbname_len = 0 , charset_len = 0 ;
zend_long session_mode = OCI_DEFAULT ;
1999-04-21 22:49:16 +00:00
2005-12-01 13:39:48 +00:00
/* if a fourth parameter is handed over, it is the charset identifier (but is only used in Oracle 9i+) */
2018-12-09 00:28:04 +00:00
ZEND_PARSE_PARAMETERS_START ( 2 , 5 )
Z_PARAM_STRING ( username , username_len )
Z_PARAM_STRING ( password , password_len )
Z_PARAM_OPTIONAL
2020-09-07 15:38:14 +00:00
Z_PARAM_STRING_OR_NULL ( dbname , dbname_len )
2018-12-09 00:28:04 +00:00
Z_PARAM_STRING ( charset , charset_len )
Z_PARAM_LONG ( session_mode )
ZEND_PARSE_PARAMETERS_END ( ) ;
2008-03-12 01:26:44 +00:00
2013-08-31 00:37:44 +00:00
# ifdef HAVE_OCI8_DTRACE
2013-08-27 23:41:02 +00:00
if ( DTRACE_OCI8_CONNECT_ENTRY_ENABLED ( ) ) {
DTRACE_OCI8_CONNECT_ENTRY ( username , dbname , charset , session_mode , persistent , exclusive ) ;
2013-07-24 22:33:22 +00:00
}
2013-08-31 00:37:44 +00:00
# endif /* HAVE_OCI8_DTRACE */
2013-07-24 22:33:22 +00:00
2005-12-01 13:39:48 +00:00
if ( ! charset_len ) {
charset = NULL ;
1999-06-09 10:40:08 +00:00
}
2008-03-12 01:26:44 +00:00
2015-08-12 11:57:16 +00:00
connection = php_oci_do_connect_ex ( username , ( int ) username_len , password , ( int ) password_len , NULL , 0 , dbname , ( int ) dbname_len , charset , session_mode , persistent , exclusive ) ;
1999-06-09 10:40:08 +00:00
2013-08-31 00:37:44 +00:00
# ifdef HAVE_OCI8_DTRACE
2013-08-27 23:41:02 +00:00
if ( DTRACE_OCI8_CONNECT_RETURN_ENABLED ( ) ) {
DTRACE_OCI8_CONNECT_RETURN ( connection ) ;
2013-07-24 22:33:22 +00:00
}
2013-08-31 00:37:44 +00:00
# endif /* HAVE_OCI8_DTRACE */
2013-07-24 22:33:22 +00:00
2005-12-01 13:39:48 +00:00
if ( ! connection ) {
RETURN_FALSE ;
1999-04-21 22:49:16 +00:00
}
2014-09-09 19:50:26 +00:00
RETURN_RES ( connection - > id ) ;
2008-03-12 01:26:44 +00:00
2013-07-24 22:33:22 +00:00
}
/* }}} */
1999-04-21 22:49:16 +00:00
2005-12-01 13:39:48 +00:00
/* {{{ php_oci_do_connect_ex()
2008-04-18 00:05:27 +00:00
*
* The real connect function . Allocates all the resources needed , establishes the connection and
* returns the result handle ( or NULL )
*/
2014-12-13 22:06:14 +00:00
php_oci_connection * php_oci_do_connect_ex ( char * username , int username_len , char * password , int password_len , char * new_password , int new_password_len , char * dbname , int dbname_len , char * charset , zend_long session_mode , int persistent , int exclusive )
2000-01-16 13:30:57 +00:00
{
2014-05-21 23:43:44 +00:00
zval * zvp ;
2020-08-22 01:37:23 +00:00
zend_resource * le = NULL ;
2014-05-21 23:43:44 +00:00
zend_resource new_le ;
2005-12-01 13:39:48 +00:00
php_oci_connection * connection = NULL ;
smart_str hashed_details = { 0 } ;
time_t timestamp ;
2008-01-31 01:33:30 +00:00
php_oci_spool * session_pool = NULL ;
2021-01-15 11:30:54 +00:00
bool use_spool = 1 ; /* Default is to use client-side session pool */
bool ping_done = 0 ;
2008-01-31 01:33:30 +00:00
2005-12-01 13:39:48 +00:00
ub2 charsetid = 0 ;
2006-08-10 12:15:58 +00:00
ub2 charsetid_nls_lang = 0 ;
2008-03-12 01:26:44 +00:00
MFH
1. Merged ARG_INFO patch (Felipe)
2. Allow empty username & password so Oracle can do non-password based
authentication, i.e. "External Authentication".
http://news.php.net/php.internals/37545
[DOC]
A new OCI_CRED_EXT flag can be passed as the "session_mode" parameter
to oci_connect(), oci_new_connect() and oci_pconnect().
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT);
This tells Oracle to do external or OS authentication, if configured
in the database.
OCI_CRED_EXT can only be used with username of "/" and a empty
password. Oci8.privileged_connection may be On or Off. OCI_CRED_EXT
is not supported on Windows for security reasons.
The new flag may be combined with the existing OCI_SYSOPER or
OCI_SYSDBA modes (note: oci8.privileged_connection needs to be On for
OCI_SYSDBA and OCI_SYSOPER), e.g.:
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT+OCI_SYSOPER);
2008-07-16 22:16:03 +00:00
if ( session_mode & ~ ( OCI_SYSOPER | OCI_SYSDBA | PHP_OCI_CRED_EXT ) ) {
2016-08-07 00:17:06 +00:00
php_error_docref ( NULL , E_WARNING , " Invalid session mode specified ( " ZEND_LONG_FMT " ) " , session_mode ) ;
MFH
1. Merged ARG_INFO patch (Felipe)
2. Allow empty username & password so Oracle can do non-password based
authentication, i.e. "External Authentication".
http://news.php.net/php.internals/37545
[DOC]
A new OCI_CRED_EXT flag can be passed as the "session_mode" parameter
to oci_connect(), oci_new_connect() and oci_pconnect().
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT);
This tells Oracle to do external or OS authentication, if configured
in the database.
OCI_CRED_EXT can only be used with username of "/" and a empty
password. Oci8.privileged_connection may be On or Off. OCI_CRED_EXT
is not supported on Windows for security reasons.
The new flag may be combined with the existing OCI_SYSOPER or
OCI_SYSDBA modes (note: oci8.privileged_connection needs to be On for
OCI_SYSDBA and OCI_SYSOPER), e.g.:
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT+OCI_SYSOPER);
2008-07-16 22:16:03 +00:00
return NULL ;
}
if ( session_mode & ( OCI_SYSOPER | OCI_SYSDBA | PHP_OCI_CRED_EXT ) ) {
if ( ( session_mode & OCI_SYSOPER ) & & ( session_mode & OCI_SYSDBA ) ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " OCI_SYSDBA and OCI_SYSOPER cannot be used together " ) ;
MFH
1. Merged ARG_INFO patch (Felipe)
2. Allow empty username & password so Oracle can do non-password based
authentication, i.e. "External Authentication".
http://news.php.net/php.internals/37545
[DOC]
A new OCI_CRED_EXT flag can be passed as the "session_mode" parameter
to oci_connect(), oci_new_connect() and oci_pconnect().
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT);
This tells Oracle to do external or OS authentication, if configured
in the database.
OCI_CRED_EXT can only be used with username of "/" and a empty
password. Oci8.privileged_connection may be On or Off. OCI_CRED_EXT
is not supported on Windows for security reasons.
The new flag may be combined with the existing OCI_SYSOPER or
OCI_SYSDBA modes (note: oci8.privileged_connection needs to be On for
OCI_SYSDBA and OCI_SYSOPER), e.g.:
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT+OCI_SYSOPER);
2008-07-16 22:16:03 +00:00
return NULL ;
}
if ( session_mode & PHP_OCI_CRED_EXT ) {
# ifdef PHP_WIN32
/* Disable external authentication on Windows as Impersonation is not yet handled.
* TODO : Re - enable this once OCI provides capability .
*/
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " External Authentication is not supported on Windows " ) ;
MFH
1. Merged ARG_INFO patch (Felipe)
2. Allow empty username & password so Oracle can do non-password based
authentication, i.e. "External Authentication".
http://news.php.net/php.internals/37545
[DOC]
A new OCI_CRED_EXT flag can be passed as the "session_mode" parameter
to oci_connect(), oci_new_connect() and oci_pconnect().
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT);
This tells Oracle to do external or OS authentication, if configured
in the database.
OCI_CRED_EXT can only be used with username of "/" and a empty
password. Oci8.privileged_connection may be On or Off. OCI_CRED_EXT
is not supported on Windows for security reasons.
The new flag may be combined with the existing OCI_SYSOPER or
OCI_SYSDBA modes (note: oci8.privileged_connection needs to be On for
OCI_SYSDBA and OCI_SYSOPER), e.g.:
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT+OCI_SYSOPER);
2008-07-16 22:16:03 +00:00
return NULL ;
# endif
if ( username_len ! = 1 | | username [ 0 ] ! = ' / ' | | password_len ! = 0 ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " OCI_CRED_EXT can only be used with a username of \" / \" and a NULL password " ) ;
MFH
1. Merged ARG_INFO patch (Felipe)
2. Allow empty username & password so Oracle can do non-password based
authentication, i.e. "External Authentication".
http://news.php.net/php.internals/37545
[DOC]
A new OCI_CRED_EXT flag can be passed as the "session_mode" parameter
to oci_connect(), oci_new_connect() and oci_pconnect().
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT);
This tells Oracle to do external or OS authentication, if configured
in the database.
OCI_CRED_EXT can only be used with username of "/" and a empty
password. Oci8.privileged_connection may be On or Off. OCI_CRED_EXT
is not supported on Windows for security reasons.
The new flag may be combined with the existing OCI_SYSOPER or
OCI_SYSDBA modes (note: oci8.privileged_connection needs to be On for
OCI_SYSDBA and OCI_SYSOPER), e.g.:
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT+OCI_SYSOPER);
2008-07-16 22:16:03 +00:00
return NULL ;
}
}
if ( session_mode & ( OCI_SYSOPER | OCI_SYSDBA ) ) {
/* Increase security by not caching privileged oci_pconnect() connections. The
* connection becomes equivalent to oci_connect ( ) or oci_new_connect ( ) .
*/
persistent = 0 ;
2005-12-01 13:39:48 +00:00
if ( ! OCI_G ( privileged_connect ) ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Privileged connect is disabled. Enable oci8.privileged_connect to be able to connect as SYSOPER or SYSDBA " ) ;
2005-12-01 13:39:48 +00:00
return NULL ;
}
MFH
1. Merged ARG_INFO patch (Felipe)
2. Allow empty username & password so Oracle can do non-password based
authentication, i.e. "External Authentication".
http://news.php.net/php.internals/37545
[DOC]
A new OCI_CRED_EXT flag can be passed as the "session_mode" parameter
to oci_connect(), oci_new_connect() and oci_pconnect().
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT);
This tells Oracle to do external or OS authentication, if configured
in the database.
OCI_CRED_EXT can only be used with username of "/" and a empty
password. Oci8.privileged_connection may be On or Off. OCI_CRED_EXT
is not supported on Windows for security reasons.
The new flag may be combined with the existing OCI_SYSOPER or
OCI_SYSDBA modes (note: oci8.privileged_connection needs to be On for
OCI_SYSDBA and OCI_SYSOPER), e.g.:
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT+OCI_SYSOPER);
2008-07-16 22:16:03 +00:00
}
2000-01-16 13:30:57 +00:00
}
2009-03-09 19:01:16 +00:00
/* Initialize global handles if they weren't initialized before */
if ( OCI_G ( env ) = = NULL ) {
2014-12-13 22:06:14 +00:00
php_oci_init_global_handles ( ) ;
2009-03-09 19:01:16 +00:00
if ( OCI_G ( env ) = = NULL ) {
return NULL ;
}
}
MFH
1. Merged ARG_INFO patch (Felipe)
2. Allow empty username & password so Oracle can do non-password based
authentication, i.e. "External Authentication".
http://news.php.net/php.internals/37545
[DOC]
A new OCI_CRED_EXT flag can be passed as the "session_mode" parameter
to oci_connect(), oci_new_connect() and oci_pconnect().
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT);
This tells Oracle to do external or OS authentication, if configured
in the database.
OCI_CRED_EXT can only be used with username of "/" and a empty
password. Oci8.privileged_connection may be On or Off. OCI_CRED_EXT
is not supported on Windows for security reasons.
The new flag may be combined with the existing OCI_SYSOPER or
OCI_SYSDBA modes (note: oci8.privileged_connection needs to be On for
OCI_SYSDBA and OCI_SYSOPER), e.g.:
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT+OCI_SYSOPER);
2008-07-16 22:16:03 +00:00
/* We cannot use the new session create logic (OCISessionGet from
* client - side session pool ) when privileged connect or password
* change is attempted or OCI_CRED_EXT mode is specified .
* TODO : Re - enable this when OCI provides support .
2008-01-31 01:33:30 +00:00
*/
MFH
1. Merged ARG_INFO patch (Felipe)
2. Allow empty username & password so Oracle can do non-password based
authentication, i.e. "External Authentication".
http://news.php.net/php.internals/37545
[DOC]
A new OCI_CRED_EXT flag can be passed as the "session_mode" parameter
to oci_connect(), oci_new_connect() and oci_pconnect().
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT);
This tells Oracle to do external or OS authentication, if configured
in the database.
OCI_CRED_EXT can only be used with username of "/" and a empty
password. Oci8.privileged_connection may be On or Off. OCI_CRED_EXT
is not supported on Windows for security reasons.
The new flag may be combined with the existing OCI_SYSOPER or
OCI_SYSDBA modes (note: oci8.privileged_connection needs to be On for
OCI_SYSDBA and OCI_SYSOPER), e.g.:
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT+OCI_SYSOPER);
2008-07-16 22:16:03 +00:00
if ( ( session_mode & ( OCI_SYSOPER | OCI_SYSDBA | PHP_OCI_CRED_EXT ) ) | | ( new_password_len ) ) {
2008-01-31 01:33:30 +00:00
use_spool = 0 ;
}
2008-03-12 01:26:44 +00:00
smart_str_appendl_ex ( & hashed_details , " oci8*** " , sizeof ( " oci8*** " ) - 1 , 0 ) ;
2005-12-01 13:39:48 +00:00
smart_str_appendl_ex ( & hashed_details , username , username_len , 0 ) ;
2008-03-12 01:26:44 +00:00
smart_str_appendl_ex ( & hashed_details , " ** " , sizeof ( " ** " ) - 1 , 0 ) ;
/* DRCP: connection_class is an attribute of a connection */
if ( OCI_G ( connection_class ) ) {
smart_str_appendl_ex ( & hashed_details , OCI_G ( connection_class ) , strlen ( OCI_G ( connection_class ) ) , 0 ) ;
}
smart_str_appendl_ex ( & hashed_details , " ** " , sizeof ( " ** " ) - 1 , 0 ) ;
2009-10-06 22:36:32 +00:00
/* Add edition attribute to the hash */
if ( OCI_G ( edition ) ) {
smart_str_appendl_ex ( & hashed_details , OCI_G ( edition ) , strlen ( OCI_G ( edition ) ) , 0 ) ;
}
smart_str_appendl_ex ( & hashed_details , " ** " , sizeof ( " ** " ) - 1 , 0 ) ;
2006-08-05 20:56:43 +00:00
if ( password_len ) {
2014-09-09 11:12:26 +00:00
zend_ulong password_hash ;
2020-05-15 08:13:38 +00:00
password_hash = zend_hash_func ( password , password_len ) ;
2006-08-05 20:56:43 +00:00
smart_str_append_unsigned_ex ( & hashed_details , password_hash , 0 ) ;
}
2008-03-12 01:26:44 +00:00
smart_str_appendl_ex ( & hashed_details , " ** " , sizeof ( " ** " ) - 1 , 0 ) ;
2006-08-05 20:56:43 +00:00
2005-12-01 13:39:48 +00:00
if ( dbname ) {
smart_str_appendl_ex ( & hashed_details , dbname , dbname_len , 0 ) ;
2004-01-02 15:32:09 +00:00
}
2008-03-12 01:26:44 +00:00
smart_str_appendl_ex ( & hashed_details , " ** " , sizeof ( " ** " ) - 1 , 0 ) ;
2000-01-16 13:30:57 +00:00
2005-12-01 13:39:48 +00:00
if ( charset & & * charset ) {
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( charsetid , OCINlsCharSetNameToId , ( OCI_G ( env ) , ( CONST oratext * ) charset ) ) ;
2006-08-10 12:15:58 +00:00
if ( ! charsetid ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " Invalid character set name: %s " , charset ) ;
2006-08-10 12:15:58 +00:00
} else {
smart_str_append_unsigned_ex ( & hashed_details , charsetid , 0 ) ;
}
2005-12-01 13:39:48 +00:00
}
2006-08-10 12:15:58 +00:00
/* use NLS_LANG if no or invalid charset specified */
if ( ! charsetid ) {
2006-03-07 07:47:43 +00:00
size_t rsize = 0 ;
2006-08-10 12:15:58 +00:00
sword result ;
2001-04-13 14:43:39 +00:00
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( result , OCINlsEnvironmentVariableGet , ( & charsetid_nls_lang , 0 , OCI_NLS_CHARSET_ID , 0 , & rsize ) ) ;
2006-08-10 12:15:58 +00:00
if ( result ! = OCI_SUCCESS ) {
charsetid_nls_lang = 0 ;
}
smart_str_append_unsigned_ex ( & hashed_details , charsetid_nls_lang , 0 ) ;
2002-11-15 17:59:19 +00:00
}
2001-04-13 14:43:39 +00:00
2005-12-01 13:39:48 +00:00
timestamp = time ( NULL ) ;
2008-03-12 01:26:44 +00:00
2005-12-01 13:39:48 +00:00
smart_str_append_unsigned_ex ( & hashed_details , session_mode , 0 ) ;
2015-10-07 09:24:49 +00:00
if ( persistent ) {
smart_str_appendl_ex ( & hashed_details , " pc " , sizeof ( " pc " ) - 1 , 0 ) ;
}
2018-09-24 10:52:58 +00:00
smart_str_0 ( & hashed_details ) ;
2005-12-01 13:39:48 +00:00
/* make it lowercase */
2021-09-24 01:40:27 +00:00
zend_str_tolower ( ZSTR_VAL ( hashed_details . s ) , ZSTR_LEN ( hashed_details . s ) ) ;
2008-03-12 01:26:44 +00:00
2005-12-01 13:39:48 +00:00
if ( ! exclusive & & ! new_password ) {
2021-01-15 11:30:54 +00:00
bool found = 0 ;
2006-08-05 20:56:43 +00:00
2014-05-21 23:43:44 +00:00
if ( persistent & & ( ( zvp = zend_hash_find ( & EG ( persistent_list ) , hashed_details . s ) ) ) ! = NULL ) {
zend_resource * le = Z_RES_P ( zvp ) ;
2006-08-05 20:56:43 +00:00
found = 1 ;
2005-12-01 13:39:48 +00:00
/* found */
if ( le - > type = = le_pconnection ) {
2008-03-12 01:26:44 +00:00
connection = ( php_oci_connection * ) le - > ptr ;
2005-12-01 13:39:48 +00:00
}
2014-05-21 23:43:44 +00:00
} else if ( ! persistent & & ( ( zvp = zend_hash_find ( & EG ( regular_list ) , hashed_details . s ) ) ! = NULL ) ) {
le = Z_RES_P ( zvp ) ;
2006-08-05 20:56:43 +00:00
found = 1 ;
2005-12-01 13:39:48 +00:00
if ( le - > type = = le_index_ptr ) {
2015-08-12 11:57:16 +00:00
zend_resource * ptr ;
2005-12-01 13:39:48 +00:00
2015-11-15 21:15:22 +00:00
ptr = ( zend_resource * ) le - > ptr ;
2015-08-12 11:57:16 +00:00
if ( ptr & & ( ptr - > type = = le_connection ) ) {
connection = ( php_oci_connection * ) ptr - > ptr ;
2005-12-01 13:39:48 +00:00
}
2002-11-15 17:59:19 +00:00
}
2005-12-01 13:39:48 +00:00
}
2013-08-31 00:37:44 +00:00
# ifdef HAVE_OCI8_DTRACE
2013-07-24 22:33:22 +00:00
if ( DTRACE_OCI8_CONNECT_LOOKUP_ENABLED ( ) ) {
DTRACE_OCI8_CONNECT_LOOKUP ( connection , connection & & connection - > is_stub ? 1 : 0 ) ;
}
2013-08-31 00:37:44 +00:00
# endif /* HAVE_OCI8_DTRACE */
2008-02-16 01:20:22 +00:00
2008-04-18 00:05:27 +00:00
/* If we got a pconnection stub, then 'load'(OCISessionGet) the real connection from its
* private spool A connection is a stub if it is only a cached structure and the real
* connection is released to its underlying private session pool . We currently do not have
* stub support for non - persistent conns .
2008-02-16 01:20:22 +00:00
*
* TODO : put in negative code for non - persistent stubs
2008-01-31 01:33:30 +00:00
*/
2008-02-16 01:20:22 +00:00
if ( connection & & connection - > is_persistent & & connection - > is_stub ) {
2015-08-12 11:57:16 +00:00
if ( php_oci_create_session ( connection , NULL , dbname , dbname_len , username , username_len , password , password_len , new_password , new_password_len , ( int ) session_mode ) ) {
2014-09-19 20:16:01 +00:00
smart_str_free ( & hashed_details ) ;
2014-05-21 23:43:44 +00:00
zend_hash_del ( & EG ( persistent_list ) , connection - > hash_key ) ;
2008-02-16 01:20:22 +00:00
return NULL ;
}
2008-03-12 01:26:44 +00:00
/* We do the ping in php_oci_create_session, no need to ping again below */
ping_done = 1 ;
2008-02-16 01:20:22 +00:00
}
2008-03-12 01:26:44 +00:00
2008-02-16 01:20:22 +00:00
if ( connection ) {
2005-12-01 13:39:48 +00:00
if ( connection - > is_open ) {
/* found an open connection. now ping it */
if ( connection - > is_persistent ) {
2008-03-12 01:26:44 +00:00
2008-04-18 00:05:27 +00:00
/* Check connection liveness in the following order:
2005-12-01 13:39:48 +00:00
* 1 ) always check OCI_ATTR_SERVER_STATUS
* 2 ) see if it ' s time to ping it
2008-02-16 01:20:22 +00:00
* 3 ) ping it if needed
2008-03-12 01:26:44 +00:00
*/
2014-12-13 22:06:14 +00:00
if ( php_oci_connection_status ( connection ) ) {
2008-04-18 00:05:27 +00:00
/* Only ping if:
*
2005-12-01 13:39:48 +00:00
* 1 ) next_ping > 0 , which means that ping_interval is not - 1 ( aka " Off " )
2008-04-18 00:05:27 +00:00
*
* 2 ) current_timestamp > next_ping , which means " it's time to check if it's
* still alive "
2008-03-12 01:26:44 +00:00
*/
2014-12-13 22:06:14 +00:00
if ( ! ping_done & & ( * ( connection - > next_pingp ) > 0 ) & & ( timestamp > = * ( connection - > next_pingp ) ) & & ! php_oci_connection_ping ( connection ) ) {
2005-12-01 13:39:48 +00:00
/* server died */
2006-08-15 13:08:34 +00:00
} else {
2015-10-07 09:24:49 +00:00
php_oci_connection * tmp = ( php_oci_connection * ) NULL ;
zval * tmp_val = ( zval * ) NULL ;
2006-05-29 10:59:30 +00:00
2005-12-01 13:39:48 +00:00
/* okay, the connection is open and the server is still alive */
connection - > used_this_request = 1 ;
2015-11-25 01:42:27 +00:00
if ( connection - > id ) {
tmp_val = zend_hash_index_find ( & EG ( regular_list ) , connection - > id - > handle ) ;
if ( ( tmp_val ! = NULL ) & & ( Z_TYPE_P ( tmp_val ) = = IS_RESOURCE ) ) {
tmp = Z_RES_VAL_P ( tmp_val ) ;
}
2018-09-24 06:38:39 +00:00
2015-11-25 01:42:27 +00:00
if ( ( tmp_val ! = NULL ) & & ( tmp ! = NULL ) & &
2022-03-31 14:27:58 +00:00
zend_string_equals ( tmp - > hash_key , hashed_details . s ) ) {
2015-11-25 01:42:27 +00:00
connection = tmp ;
2018-09-24 10:05:54 +00:00
GC_ADDREF ( connection - > id ) ;
2015-11-25 01:42:27 +00:00
}
2006-05-29 10:59:30 +00:00
} else {
2013-07-24 22:33:22 +00:00
PHP_OCI_REGISTER_RESOURCE ( connection , le_pconnection ) ;
2008-04-18 00:05:27 +00:00
/* Persistent connections: For old close semantics we artificially
* bump up the refcount to prevent the non - persistent destructor
* from getting called until request shutdown . The refcount is
* decremented in the persistent helper
*/
if ( OCI_G ( old_oci_close_semantics ) ) {
2018-09-24 10:05:54 +00:00
GC_ADDREF ( connection - > id ) ;
2008-04-18 00:05:27 +00:00
}
2006-04-12 17:59:32 +00:00
}
2014-09-19 20:16:01 +00:00
smart_str_free ( & hashed_details ) ;
2005-12-01 13:39:48 +00:00
return connection ;
}
}
/* server died */
2006-08-15 13:08:34 +00:00
} else {
2005-12-01 13:39:48 +00:00
/* we do not ping non-persistent connections */
2014-09-19 20:16:01 +00:00
smart_str_free ( & hashed_details ) ;
2018-09-24 10:05:54 +00:00
GC_ADDREF ( connection - > id ) ;
2005-12-01 13:39:48 +00:00
return connection ;
2005-10-10 10:44:39 +00:00
}
2008-03-22 01:27:50 +00:00
} /* is_open is true? */
2008-04-18 00:05:27 +00:00
/* Server died - connection not usable. The is_open=true can also fall through to here,
* if ping fails
*/
2008-03-22 01:27:50 +00:00
if ( persistent ) {
connection - > is_open = 0 ;
connection - > used_this_request = 1 ;
MFH
1. Merged ARG_INFO patch (Felipe)
2. Allow empty username & password so Oracle can do non-password based
authentication, i.e. "External Authentication".
http://news.php.net/php.internals/37545
[DOC]
A new OCI_CRED_EXT flag can be passed as the "session_mode" parameter
to oci_connect(), oci_new_connect() and oci_pconnect().
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT);
This tells Oracle to do external or OS authentication, if configured
in the database.
OCI_CRED_EXT can only be used with username of "/" and a empty
password. Oci8.privileged_connection may be On or Off. OCI_CRED_EXT
is not supported on Windows for security reasons.
The new flag may be combined with the existing OCI_SYSOPER or
OCI_SYSDBA modes (note: oci8.privileged_connection needs to be On for
OCI_SYSDBA and OCI_SYSOPER), e.g.:
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT+OCI_SYSOPER);
2008-07-16 22:16:03 +00:00
2008-04-18 00:05:27 +00:00
/* We have to do a hash_del but need to preserve the resource if there is a positive
* refcount . Set the data pointer in the list entry to NULL
*/
2020-08-22 01:37:23 +00:00
if ( connection = = connection - > id - > ptr & & le ) {
2008-03-22 01:27:50 +00:00
le - > ptr = NULL ;
}
MFH
1. Merged ARG_INFO patch (Felipe)
2. Allow empty username & password so Oracle can do non-password based
authentication, i.e. "External Authentication".
http://news.php.net/php.internals/37545
[DOC]
A new OCI_CRED_EXT flag can be passed as the "session_mode" parameter
to oci_connect(), oci_new_connect() and oci_pconnect().
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT);
This tells Oracle to do external or OS authentication, if configured
in the database.
OCI_CRED_EXT can only be used with username of "/" and a empty
password. Oci8.privileged_connection may be On or Off. OCI_CRED_EXT
is not supported on Windows for security reasons.
The new flag may be combined with the existing OCI_SYSOPER or
OCI_SYSDBA modes (note: oci8.privileged_connection needs to be On for
OCI_SYSDBA and OCI_SYSOPER), e.g.:
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT+OCI_SYSOPER);
2008-07-16 22:16:03 +00:00
2014-05-21 23:43:44 +00:00
zend_hash_del ( & EG ( persistent_list ) , hashed_details . s ) ;
2000-01-16 13:30:57 +00:00
} else {
2008-04-18 00:05:27 +00:00
/* We only remove the hash entry. The resource and the list entry with its pointer
* to the resource are still intact
*/
2014-05-21 23:43:44 +00:00
zend_hash_del ( & EG ( regular_list ) , hashed_details . s ) ;
2000-01-16 13:30:57 +00:00
}
2008-03-22 01:27:50 +00:00
connection = NULL ;
2008-02-16 01:20:22 +00:00
} else if ( found ) {
2005-12-01 13:39:48 +00:00
/* found something, but it's not a connection, delete it */
if ( persistent ) {
2014-05-21 23:43:44 +00:00
zend_hash_del ( & EG ( persistent_list ) , hashed_details . s ) ;
2006-08-15 13:08:34 +00:00
} else {
2014-05-21 23:43:44 +00:00
zend_hash_del ( & EG ( regular_list ) , hashed_details . s ) ;
2005-12-01 13:39:48 +00:00
}
}
}
2008-01-31 01:33:30 +00:00
2008-04-18 00:05:27 +00:00
/* Check if we have reached max_persistent. If so, try to remove a few timed-out connections. As
* a last resort , return a non - persistent connection .
2008-01-31 01:33:30 +00:00
*/
2008-02-16 01:20:22 +00:00
if ( persistent ) {
2021-01-15 11:30:54 +00:00
bool alloc_non_persistent = 0 ;
2008-03-12 01:26:44 +00:00
2008-08-28 06:33:24 +00:00
if ( OCI_G ( max_persistent ) ! = - 1 & & OCI_G ( num_persistent ) > = OCI_G ( max_persistent ) ) {
2008-02-16 01:20:22 +00:00
/* try to find an idle connection and kill it */
2015-06-27 06:09:05 +00:00
zend_hash_apply ( & EG ( persistent_list ) , php_oci_persistent_helper ) ;
2008-03-12 01:26:44 +00:00
2008-08-28 06:33:24 +00:00
if ( OCI_G ( max_persistent ) ! = - 1 & & OCI_G ( num_persistent ) > = OCI_G ( max_persistent ) ) {
2008-02-16 01:20:22 +00:00
/* all persistent connactions are in use, fallback to non-persistent connection creation */
2016-08-07 00:17:06 +00:00
php_error_docref ( NULL , E_NOTICE , " Too many open persistent connections ( " ZEND_LONG_FMT " ) " , OCI_G ( num_persistent ) ) ;
2008-02-16 01:20:22 +00:00
alloc_non_persistent = 1 ;
2008-01-31 01:33:30 +00:00
}
2008-02-16 01:20:22 +00:00
}
2008-03-12 01:26:44 +00:00
2008-02-16 01:20:22 +00:00
if ( alloc_non_persistent ) {
2005-12-01 13:39:48 +00:00
connection = ( php_oci_connection * ) ecalloc ( 1 , sizeof ( php_oci_connection ) ) ;
2014-08-25 17:24:55 +00:00
connection - > hash_key = zend_string_dup ( hashed_details . s , 0 ) ;
2005-12-01 13:39:48 +00:00
connection - > is_persistent = 0 ;
2017-04-07 18:40:40 +00:00
ZVAL_UNDEF ( & connection - > taf_callback ) ;
2013-09-27 04:12:11 +00:00
# ifdef HAVE_OCI8_DTRACE
connection - > client_id = NULL ;
# endif
2008-02-16 01:20:22 +00:00
} else {
connection = ( php_oci_connection * ) calloc ( 1 , sizeof ( php_oci_connection ) ) ;
2011-11-18 09:59:35 +00:00
if ( connection = = NULL ) {
return NULL ;
}
2014-08-25 17:24:55 +00:00
connection - > hash_key = zend_string_dup ( hashed_details . s , 1 ) ;
2011-11-18 09:59:35 +00:00
if ( connection - > hash_key = = NULL ) {
free ( connection ) ;
return NULL ;
}
2008-02-16 01:20:22 +00:00
connection - > is_persistent = 1 ;
2017-04-07 18:40:40 +00:00
ZVAL_UNDEF ( & connection - > taf_callback ) ;
2013-09-27 04:12:11 +00:00
# ifdef HAVE_OCI8_DTRACE
connection - > client_id = NULL ;
# endif
2005-12-01 13:39:48 +00:00
}
2008-02-16 01:20:22 +00:00
} else {
connection = ( php_oci_connection * ) ecalloc ( 1 , sizeof ( php_oci_connection ) ) ;
2014-08-25 17:24:55 +00:00
connection - > hash_key = zend_string_dup ( hashed_details . s , 0 ) ;
2008-02-16 01:20:22 +00:00
connection - > is_persistent = 0 ;
2017-04-07 18:40:40 +00:00
ZVAL_UNDEF ( & connection - > taf_callback ) ;
2013-09-27 04:12:11 +00:00
# ifdef HAVE_OCI8_DTRACE
connection - > client_id = NULL ;
# endif
2001-02-12 14:36:28 +00:00
}
2001-08-15 16:00:56 +00:00
2008-04-18 00:05:27 +00:00
/* {{{ Get the session pool that suits this connection request from the persistent list. This
* step is only for non - persistent connections as persistent connections have private session
* pools . Non - persistent conns use shared session pool to allow for optimizations such as
* caching the physical connection ( for DRCP ) even when the non - persistent php connection is
* destroyed .
*
* TODO : Unconditionally do this once OCI provides extended OCISessionGet capability
*/
2008-01-31 01:33:30 +00:00
if ( use_spool & & ! connection - > is_persistent ) {
2014-12-13 22:06:14 +00:00
if ( ( session_pool = php_oci_get_spool ( username , username_len , password , password_len , dbname , dbname_len , charsetid ? charsetid : charsetid_nls_lang ) ) = = NULL )
2008-01-31 01:33:30 +00:00
{
2014-12-13 22:06:14 +00:00
php_oci_connection_close ( connection ) ;
2014-09-19 20:16:01 +00:00
smart_str_free ( & hashed_details ) ;
2008-01-31 01:33:30 +00:00
return NULL ;
2008-02-16 01:20:22 +00:00
}
2013-07-24 22:33:22 +00:00
}
/* }}} */
2008-01-31 01:33:30 +00:00
2005-12-01 13:39:48 +00:00
connection - > idle_expiry = ( OCI_G ( persistent_timeout ) > 0 ) ? ( timestamp + OCI_G ( persistent_timeout ) ) : 0 ;
2007-08-06 20:32:55 +00:00
2008-04-18 00:05:27 +00:00
/* Mark password as unchanged by PHP during the duration of the database session */
2007-08-06 20:32:55 +00:00
connection - > passwd_changed = 0 ;
2008-03-12 01:26:44 +00:00
2014-09-19 20:16:01 +00:00
smart_str_free ( & hashed_details ) ;
1999-04-21 22:49:16 +00:00
2006-08-10 12:15:58 +00:00
if ( charsetid ) {
2005-12-01 13:39:48 +00:00
connection - > charset = charsetid ;
2006-08-10 12:15:58 +00:00
} else {
connection - > charset = charsetid_nls_lang ;
1999-05-12 14:28:01 +00:00
}
2008-04-18 00:05:27 +00:00
/* Old session creation semantics when session pool cannot be used Eg: privileged
* connect / password change
*/
if ( ! use_spool ) {
2015-08-12 11:57:16 +00:00
if ( php_oci_old_create_session ( connection , dbname , dbname_len , username , username_len , password , password_len , new_password , new_password_len , ( int ) session_mode ) ) {
2014-12-13 22:06:14 +00:00
php_oci_connection_close ( connection ) ;
2005-12-01 13:39:48 +00:00
return NULL ;
}
2008-03-12 01:26:44 +00:00
} else {
2008-01-31 01:33:30 +00:00
/* create using the client-side session pool */
2015-08-12 11:57:16 +00:00
if ( php_oci_create_session ( connection , session_pool , dbname , dbname_len , username , username_len , password , password_len , new_password , new_password_len , ( int ) session_mode ) ) {
2014-12-13 22:06:14 +00:00
php_oci_connection_close ( connection ) ;
2005-12-01 13:39:48 +00:00
return NULL ;
2008-01-31 01:33:30 +00:00
}
1999-04-21 22:49:16 +00:00
}
2008-03-12 01:26:44 +00:00
2008-04-18 00:05:27 +00:00
/* Mark it as open */
2005-12-01 13:39:48 +00:00
connection - > is_open = 1 ;
2008-01-31 01:33:30 +00:00
2008-02-16 01:20:22 +00:00
/* add to the appropriate hash */
2005-12-01 13:39:48 +00:00
if ( connection - > is_persistent ) {
connection - > used_this_request = 1 ;
2013-07-24 22:33:22 +00:00
PHP_OCI_REGISTER_RESOURCE ( connection , le_pconnection ) ;
2008-04-18 00:05:27 +00:00
/* Persistent connections: For old close semantics we artificially bump up the refcount to
* prevent the non - persistent destructor from getting called until request shutdown . The
* refcount is decremented in the persistent helper
*/
if ( OCI_G ( old_oci_close_semantics ) ) {
2018-09-24 10:05:54 +00:00
GC_ADDREF ( connection - > id ) ;
2008-04-18 00:05:27 +00:00
}
2018-09-24 10:05:54 +00:00
zend_register_persistent_resource_ex ( connection - > hash_key , connection , le_pconnection ) ;
2008-02-16 01:20:22 +00:00
OCI_G ( num_persistent ) + + ;
2008-08-28 06:33:24 +00:00
OCI_G ( num_links ) + + ;
2008-02-16 01:20:22 +00:00
} else if ( ! exclusive ) {
2013-07-24 22:33:22 +00:00
PHP_OCI_REGISTER_RESOURCE ( connection , le_connection ) ;
2014-09-09 19:50:26 +00:00
new_le . ptr = connection - > id ;
2008-02-16 01:20:22 +00:00
new_le . type = le_index_ptr ;
2014-05-21 23:43:44 +00:00
zend_hash_update_mem ( & EG ( regular_list ) , connection - > hash_key , ( void * ) & new_le , sizeof ( zend_resource ) ) ;
2008-02-16 01:20:22 +00:00
OCI_G ( num_links ) + + ;
} else {
2013-07-24 22:33:22 +00:00
PHP_OCI_REGISTER_RESOURCE ( connection , le_connection ) ;
2008-02-16 01:20:22 +00:00
OCI_G ( num_links ) + + ;
2008-01-31 01:33:30 +00:00
}
2013-08-31 00:37:44 +00:00
# ifdef HAVE_OCI8_DTRACE
2013-07-24 22:33:22 +00:00
if ( DTRACE_OCI8_CONNECT_TYPE_ENABLED ( ) ) {
DTRACE_OCI8_CONNECT_TYPE ( connection - > is_persistent ? 1 : 0 , exclusive ? 1 : 0 , connection , OCI_G ( num_persistent ) , OCI_G ( num_links ) ) ;
}
2013-08-31 00:37:44 +00:00
# endif /* HAVE_OCI8_DTRACE */
2008-02-16 01:20:22 +00:00
2005-12-01 13:39:48 +00:00
return connection ;
1999-04-21 22:49:16 +00:00
}
/* }}} */
2005-12-01 13:39:48 +00:00
/* {{{ php_oci_connection_ping()
2008-04-18 00:05:27 +00:00
*
* Ping connection . Uses OCIPing ( ) or OCIServerVersion ( ) depending on the Oracle Client version
*/
2014-12-13 22:06:14 +00:00
static int php_oci_connection_ping ( php_oci_connection * connection )
2001-04-13 14:43:39 +00:00
{
2013-09-06 01:18:29 +00:00
sword errstatus ;
OCI_G ( errcode ) = 0 ; /* assume ping is successful */
2021-12-12 02:32:34 +00:00
/* If OCIPing returns ORA-1010 (invalid OCI operation) such as from
* pre - 10.1 servers , the error is still from the server and we would have
* successfully performed a roundtrip and validated the connection .
2008-02-16 01:20:22 +00:00
*/
2013-09-06 01:18:29 +00:00
PHP_OCI_CALL_RETURN ( errstatus , OCIPing , ( connection - > svc , OCI_G ( err ) , OCI_DEFAULT ) ) ;
2008-03-12 01:26:44 +00:00
2013-09-06 01:18:29 +00:00
if ( errstatus = = OCI_SUCCESS ) {
2005-12-01 13:39:48 +00:00
return 1 ;
2008-03-12 01:26:44 +00:00
} else {
2008-02-16 01:20:22 +00:00
sb4 error_code = 0 ;
2015-07-30 10:25:40 +00:00
text tmp_buf [ PHP_OCI_ERRBUF_LEN ] ;
2005-12-01 13:39:48 +00:00
2008-02-16 01:20:22 +00:00
/* Treat ORA-1010 as a successful Ping */
2015-07-30 10:25:40 +00:00
OCIErrorGet ( OCI_G ( err ) , ( ub4 ) 1 , NULL , & error_code , tmp_buf , ( ub4 ) PHP_OCI_ERRBUF_LEN , ( ub4 ) OCI_HTYPE_ERROR ) ;
2008-02-16 01:20:22 +00:00
if ( error_code = = 1010 ) {
return 1 ;
}
2013-09-06 01:18:29 +00:00
OCI_G ( errcode ) = error_code ;
2008-02-16 01:20:22 +00:00
}
2005-12-01 13:39:48 +00:00
return 0 ;
2001-04-13 14:43:39 +00:00
}
2001-06-06 13:06:12 +00:00
/* }}} */
2001-04-13 14:43:39 +00:00
2005-12-01 13:39:48 +00:00
/* {{{ php_oci_connection_status()
2008-04-18 00:05:27 +00:00
*
* Check connection status ( pre - ping check )
*/
2014-12-13 22:06:14 +00:00
static int php_oci_connection_status ( php_oci_connection * connection )
2001-04-13 14:43:39 +00:00
{
2013-09-06 01:18:29 +00:00
ub4 ss = OCI_SERVER_NOT_CONNECTED ;
sword errstatus ;
2001-05-22 23:16:03 +00:00
2005-12-01 13:39:48 +00:00
/* get OCI_ATTR_SERVER_STATUS */
2013-09-06 01:18:29 +00:00
PHP_OCI_CALL_RETURN ( errstatus , OCIAttrGet , ( ( dvoid * ) connection - > server , OCI_HTYPE_SERVER , ( dvoid * ) & ss , ( ub4 * ) 0 , OCI_ATTR_SERVER_STATUS , OCI_G ( err ) ) ) ;
2008-03-12 01:26:44 +00:00
2013-09-06 01:18:29 +00:00
if ( errstatus = = OCI_SUCCESS & & ss = = OCI_SERVER_NORMAL ) {
2005-12-01 13:39:48 +00:00
return 1 ;
2002-11-15 17:59:19 +00:00
}
2001-04-13 14:43:39 +00:00
2013-09-06 01:18:29 +00:00
/* ignore errors here, just return failure */
2005-12-01 13:39:48 +00:00
return 0 ;
2001-04-13 14:43:39 +00:00
}
/* }}} */
2005-12-01 13:39:48 +00:00
/* {{{ php_oci_connection_rollback()
2008-04-18 00:05:27 +00:00
*
* Rollback connection
*/
2014-12-13 22:06:14 +00:00
int php_oci_connection_rollback ( php_oci_connection * connection )
2001-04-13 14:43:39 +00:00
{
2013-09-06 01:18:29 +00:00
sword errstatus ;
PHP_OCI_CALL_RETURN ( errstatus , OCITransRollback , ( connection - > svc , connection - > err , ( ub4 ) 0 ) ) ;
2013-07-24 22:33:22 +00:00
connection - > rb_on_disconnect = 0 ;
2001-04-13 14:43:39 +00:00
2013-09-06 01:18:29 +00:00
if ( errstatus ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
connection - > errcode = php_oci_error ( connection - > err , errstatus ) ;
2005-12-01 13:39:48 +00:00
PHP_OCI_HANDLE_ERROR ( connection , connection - > errcode ) ;
return 1 ;
}
2013-09-06 01:18:29 +00:00
connection - > errcode = 0 ; /* retain backwards compat with OCI8 1.4 */
2005-12-01 13:39:48 +00:00
return 0 ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2001-04-13 14:43:39 +00:00
2005-12-01 13:39:48 +00:00
/* {{{ php_oci_connection_commit()
2008-04-18 00:05:27 +00:00
*
* Commit connection
*/
2014-12-13 22:06:14 +00:00
int php_oci_connection_commit ( php_oci_connection * connection )
2005-12-01 13:39:48 +00:00
{
2013-09-06 01:18:29 +00:00
sword errstatus ;
PHP_OCI_CALL_RETURN ( errstatus , OCITransCommit , ( connection - > svc , connection - > err , ( ub4 ) 0 ) ) ;
2013-07-24 22:33:22 +00:00
connection - > rb_on_disconnect = 0 ;
2001-09-11 21:03:58 +00:00
2013-09-06 01:18:29 +00:00
if ( errstatus ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
connection - > errcode = php_oci_error ( connection - > err , errstatus ) ;
2005-12-01 13:39:48 +00:00
PHP_OCI_HANDLE_ERROR ( connection , connection - > errcode ) ;
return 1 ;
}
2013-09-06 01:18:29 +00:00
connection - > errcode = 0 ; /* retain backwards compat with OCI8 1.4 */
2005-12-01 13:39:48 +00:00
return 0 ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2002-11-15 17:59:19 +00:00
2008-02-16 01:20:22 +00:00
/* {{{ php_oci_connection_close()
2008-04-18 00:05:27 +00:00
*
* Close the connection and free all its resources
*/
2014-12-13 22:06:14 +00:00
static int php_oci_connection_close ( php_oci_connection * connection )
2005-12-01 13:39:48 +00:00
{
int result = 0 ;
2021-01-15 11:30:54 +00:00
bool in_call_save = OCI_G ( in_call ) ;
2002-11-15 17:59:19 +00:00
2013-09-06 15:54:19 +00:00
# ifdef HAVE_OCI8_DTRACE
if ( DTRACE_OCI8_CONNECTION_CLOSE_ENABLED ( ) ) {
DTRACE_OCI8_CONNECTION_CLOSE ( connection ) ;
}
# endif /* HAVE_OCI8_DTRACE */
2008-04-18 00:05:27 +00:00
if ( ! connection - > is_stub ) {
/* Release resources associated with connection */
2014-12-13 22:06:14 +00:00
php_oci_connection_release ( connection ) ;
2001-04-13 14:43:39 +00:00
}
2008-04-18 00:05:27 +00:00
if ( ! connection - > using_spool & & connection - > svc ) {
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL ( OCISessionEnd , ( connection - > svc , connection - > err , connection - > session , ( ub4 ) 0 ) ) ;
2005-12-01 13:39:48 +00:00
}
2008-01-31 01:33:30 +00:00
2005-12-01 13:39:48 +00:00
if ( connection - > err ) {
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL ( OCIHandleFree , ( ( dvoid * ) connection - > err , ( ub4 ) OCI_HTYPE_ERROR ) ) ;
2005-12-01 13:39:48 +00:00
}
2008-01-31 01:33:30 +00:00
if ( connection - > authinfo ) {
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL ( OCIHandleFree , ( ( dvoid * ) connection - > authinfo , ( ub4 ) OCI_HTYPE_AUTHINFO ) ) ;
2005-12-01 13:39:48 +00:00
}
2008-03-12 01:26:44 +00:00
/* No Handlefrees for session pool connections */
if ( ! connection - > using_spool ) {
2008-01-31 01:33:30 +00:00
if ( connection - > session ) {
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL ( OCIHandleFree , ( ( dvoid * ) connection - > session , OCI_HTYPE_SESSION ) ) ;
2008-01-31 01:33:30 +00:00
}
2008-03-12 01:26:44 +00:00
2008-01-31 01:33:30 +00:00
if ( connection - > is_attached ) {
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL ( OCIServerDetach , ( connection - > server , OCI_G ( err ) , OCI_DEFAULT ) ) ;
2008-01-31 01:33:30 +00:00
}
2008-03-12 01:26:44 +00:00
2008-01-31 01:33:30 +00:00
if ( connection - > svc ) {
2013-08-30 18:14:20 +00:00
PHP_OCI_CALL ( OCIHandleFree , ( ( dvoid * ) connection - > svc , ( ub4 ) OCI_HTYPE_SVCCTX ) ) ;
2008-01-31 01:33:30 +00:00
}
2008-03-12 01:26:44 +00:00
2008-01-31 01:33:30 +00:00
if ( connection - > server ) {
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL ( OCIHandleFree , ( ( dvoid * ) connection - > server , ( ub4 ) OCI_HTYPE_SERVER ) ) ;
2008-01-31 01:33:30 +00:00
}
2008-03-12 01:26:44 +00:00
2008-01-31 01:33:30 +00:00
if ( connection - > env ) {
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL ( OCIHandleFree , ( ( dvoid * ) connection - > env , OCI_HTYPE_ENV ) ) ;
2008-01-31 01:33:30 +00:00
}
2008-03-12 01:26:44 +00:00
} else if ( connection - > private_spool ) {
2008-02-16 01:20:22 +00:00
/* Keep this as the last member to be freed, as there are dependencies
2008-01-31 01:33:30 +00:00
* ( like env ) on the session pool
*/
2014-12-13 22:06:14 +00:00
php_oci_spool_close ( connection - > private_spool ) ;
2015-07-13 01:50:00 +00:00
connection - > private_spool = NULL ;
2005-12-01 13:39:48 +00:00
}
2001-04-13 14:43:39 +00:00
2015-10-07 09:24:49 +00:00
if ( GC_REFCOUNT ( connection - > hash_key ) > = 2 ) {
zend_hash_del ( & EG ( regular_list ) , connection - > hash_key ) ;
}
2013-09-27 04:12:11 +00:00
if ( connection - > hash_key ) {
pefree ( connection - > hash_key , connection - > is_persistent ) ;
2015-07-13 01:50:00 +00:00
connection - > hash_key = NULL ;
2013-09-27 04:12:11 +00:00
}
# ifdef HAVE_OCI8_DTRACE
if ( connection - > client_id ) {
pefree ( connection - > client_id , connection - > is_persistent ) ;
2015-07-13 01:50:00 +00:00
connection - > client_id = NULL ;
2001-04-13 14:43:39 +00:00
}
2013-09-27 04:12:11 +00:00
# endif /* HAVE_OCI8_DTRACE */
2017-04-07 18:40:40 +00:00
if ( ! Z_ISUNDEF ( connection - > taf_callback ) ) {
/* If it's NULL, then its value should be freed already */
if ( ! Z_ISNULL ( connection - > taf_callback ) ) {
zval_ptr_dtor ( & connection - > taf_callback ) ;
}
ZVAL_UNDEF ( & connection - > taf_callback ) ;
}
2013-09-27 04:12:11 +00:00
pefree ( connection , connection - > is_persistent ) ;
2005-12-01 13:39:48 +00:00
connection = NULL ;
2006-08-21 16:41:13 +00:00
OCI_G ( in_call ) = in_call_save ;
2005-12-01 13:39:48 +00:00
return result ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2001-04-13 14:43:39 +00:00
2008-02-16 01:20:22 +00:00
/* {{{ php_oci_connection_release()
2008-04-18 00:05:27 +00:00
*
* Release the connection ' s resources . This involves freeing descriptors and rolling back
* transactions , setting timeout - related parameters etc . For session - pool using connections , the
* underlying connection is released to its session pool .
*/
2014-12-13 22:06:14 +00:00
int php_oci_connection_release ( php_oci_connection * connection )
2008-01-31 01:33:30 +00:00
{
int result = 0 ;
2021-01-15 11:30:54 +00:00
bool in_call_save = OCI_G ( in_call ) ;
2008-04-18 00:05:27 +00:00
time_t timestamp = time ( NULL ) ;
2008-01-31 01:33:30 +00:00
2008-04-18 00:05:27 +00:00
if ( connection - > is_stub ) {
return 0 ;
2008-01-31 01:33:30 +00:00
}
if ( connection - > descriptors ) {
2014-12-13 22:06:14 +00:00
php_oci_connection_descriptors_free ( connection ) ;
2008-01-31 01:33:30 +00:00
}
2008-03-12 01:26:44 +00:00
if ( connection - > svc ) {
2008-01-31 01:33:30 +00:00
/* rollback outstanding transactions */
2013-07-24 22:33:22 +00:00
if ( connection - > rb_on_disconnect ) {
2014-12-13 22:06:14 +00:00
if ( php_oci_connection_rollback ( connection ) ) {
2008-01-31 01:33:30 +00:00
/* rollback failed */
result = 1 ;
}
}
}
2008-04-18 00:05:27 +00:00
if ( OCI_G ( persistent_timeout ) > 0 ) {
connection - > idle_expiry = timestamp + OCI_G ( persistent_timeout ) ;
}
/* We may have half-cooked connections to clean up */
if ( connection - > next_pingp ) {
2008-03-12 01:26:44 +00:00
if ( OCI_G ( ping_interval ) > = 0 ) {
2008-04-18 00:05:27 +00:00
* ( connection - > next_pingp ) = timestamp + OCI_G ( ping_interval ) ;
2008-03-12 01:26:44 +00:00
} else {
/* ping_interval is -1 */
* ( connection - > next_pingp ) = 0 ;
}
2008-01-31 01:33:30 +00:00
}
2008-04-18 00:05:27 +00:00
/* Release the session (stubs are filtered out at the beginning)*/
if ( connection - > using_spool ) {
ub4 rlsMode = OCI_DEFAULT ;
2008-01-31 01:33:30 +00:00
2008-04-18 00:05:27 +00:00
if ( result ) {
rlsMode | = OCI_SESSRLS_DROPSESS ;
}
2008-01-31 01:33:30 +00:00
2008-04-18 00:05:27 +00:00
if ( connection - > svc ) {
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL ( OCISessionRelease , ( connection - > svc , connection - > err , NULL ,
2008-04-18 00:05:27 +00:00
0 , rlsMode ) ) ;
}
/* It no longer has relation with the database session. However authinfo and env are
* cached
*/
connection - > svc = NULL ;
connection - > server = NULL ;
connection - > session = NULL ;
2008-03-12 01:26:44 +00:00
2013-07-24 22:33:22 +00:00
connection - > is_attached = connection - > is_open = connection - > rb_on_disconnect = connection - > used_this_request = 0 ;
2008-04-18 00:05:27 +00:00
connection - > is_stub = 1 ;
/* Cut the link between the connection structure and the time_t structure allocated within
* the OCI session
*/
connection - > next_pingp = NULL ;
2013-09-27 04:12:11 +00:00
# ifdef HAVE_OCI8_DTRACE
if ( connection - > client_id ) {
pefree ( connection - > client_id , connection - > is_persistent ) ;
connection - > client_id = NULL ;
}
# endif /* HAVE_OCI8_DTRACE */
2008-01-31 01:33:30 +00:00
}
2018-09-04 12:19:04 +00:00
/* Always set id to null, so next time a new resource is being registered. */
connection - > id = NULL ;
2008-01-31 01:33:30 +00:00
OCI_G ( in_call ) = in_call_save ;
return result ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2008-01-31 01:33:30 +00:00
2005-12-01 13:39:48 +00:00
/* {{{ php_oci_password_change()
2008-04-18 00:05:27 +00:00
*
* Change password for the user with the username given
*/
2014-12-13 22:06:14 +00:00
int php_oci_password_change ( php_oci_connection * connection , char * user , int user_len , char * pass_old , int pass_old_len , char * pass_new , int pass_new_len )
2001-04-13 14:43:39 +00:00
{
2013-09-06 01:18:29 +00:00
sword errstatus ;
PHP_OCI_CALL_RETURN ( errstatus , OCIPasswordChange , ( connection - > svc , connection - > err , ( text * ) user , user_len , ( text * ) pass_old , pass_old_len , ( text * ) pass_new , pass_new_len , OCI_DEFAULT ) ) ;
2001-04-13 14:43:39 +00:00
2013-09-06 01:18:29 +00:00
if ( errstatus ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
connection - > errcode = php_oci_error ( connection - > err , errstatus ) ;
2005-12-01 13:39:48 +00:00
PHP_OCI_HANDLE_ERROR ( connection , connection - > errcode ) ;
return 1 ;
}
2013-09-06 01:18:29 +00:00
connection - > errcode = 0 ; /* retain backwards compat with OCI8 1.4 */
2007-08-06 20:32:55 +00:00
connection - > passwd_changed = 1 ;
2005-12-01 13:39:48 +00:00
return 0 ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2011-06-10 17:38:07 +00:00
/* {{{ php_oci_client_get_version()
*
* Get Oracle client library version
*/
2015-07-30 10:25:40 +00:00
void php_oci_client_get_version ( char * version , size_t version_size )
2011-06-10 17:38:07 +00:00
{
sword major_version = 0 ;
2015-01-03 09:22:58 +00:00
sword minor_version = 0 ;
2011-06-10 17:38:07 +00:00
sword update_num = 0 ;
sword patch_num = 0 ;
sword port_update_num = 0 ;
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL ( OCIClientVersion , ( & major_version , & minor_version , & update_num , & patch_num , & port_update_num ) ) ;
2015-07-30 10:25:40 +00:00
snprintf ( version , version_size , " %d.%d.%d.%d.%d " , major_version , minor_version , update_num , patch_num , port_update_num ) ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2011-06-10 17:38:07 +00:00
2008-02-16 01:20:22 +00:00
/* {{{ php_oci_server_get_version()
2008-04-18 00:05:27 +00:00
*
* Get Oracle server version
*/
2015-07-30 10:25:40 +00:00
int php_oci_server_get_version ( php_oci_connection * connection , char * version , size_t version_size )
2005-12-01 13:39:48 +00:00
{
2013-09-06 01:18:29 +00:00
sword errstatus ;
2001-04-13 14:43:39 +00:00
2015-08-12 11:57:16 +00:00
PHP_OCI_CALL_RETURN ( errstatus , OCIServerVersion , ( connection - > svc , connection - > err , ( text * ) version , ( ub4 ) version_size , OCI_HTYPE_SVCCTX ) ) ;
2008-03-12 01:26:44 +00:00
2013-09-06 01:18:29 +00:00
if ( errstatus ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
connection - > errcode = php_oci_error ( connection - > err , errstatus ) ;
2005-12-01 13:39:48 +00:00
PHP_OCI_HANDLE_ERROR ( connection , connection - > errcode ) ;
return 1 ;
2001-04-13 14:43:39 +00:00
}
2008-03-12 01:26:44 +00:00
2005-12-01 13:39:48 +00:00
return 0 ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2001-04-13 14:43:39 +00:00
2008-02-16 01:20:22 +00:00
/* {{{ php_oci_column_to_zval()
2008-04-18 00:05:27 +00:00
*
* Convert php_oci_out_column struct into zval
*/
2014-12-13 22:06:14 +00:00
int php_oci_column_to_zval ( php_oci_out_column * column , zval * value , int mode )
2001-04-13 14:43:39 +00:00
{
2005-12-01 13:39:48 +00:00
php_oci_descriptor * descriptor ;
ub4 lob_length ;
int column_size ;
2015-07-30 10:25:40 +00:00
char * lob_buffer = ( char * ) 0 ;
2008-01-15 20:44:31 +00:00
int lob_fetch_status ;
2008-01-31 01:33:30 +00:00
2008-02-16 01:20:22 +00:00
if ( column - > indicator = = - 1 ) { /* column is NULL */
ZVAL_NULL ( value ) ;
2005-12-01 13:39:48 +00:00
return 0 ;
}
2008-03-12 01:26:44 +00:00
2005-12-01 13:39:48 +00:00
if ( column - > is_cursor ) { /* REFCURSOR -> simply return the statement id */
2015-06-27 06:09:05 +00:00
ZVAL_RES ( value , column - > stmtid ) ;
2018-09-24 10:05:54 +00:00
GC_ADDREF ( column - > stmtid ) ;
2006-08-15 13:08:34 +00:00
} else if ( column - > is_descr ) {
2008-03-12 01:26:44 +00:00
2005-12-01 13:39:48 +00:00
if ( column - > data_type ! = SQLT_RDD ) {
2008-03-12 01:26:44 +00:00
2005-12-01 13:39:48 +00:00
/* reset descriptor's length */
2014-09-09 19:50:26 +00:00
descriptor = ( php_oci_descriptor * ) column - > descid - > ptr ;
2001-09-11 21:03:58 +00:00
2015-07-13 01:50:00 +00:00
if ( ! descriptor ) {
2021-08-31 08:46:22 +00:00
php_error_docref ( NULL , E_WARNING , " Unable to find LOB descriptor # " ZEND_LONG_FMT , column - > descid - > handle ) ;
2005-12-01 13:39:48 +00:00
return 1 ;
2001-09-11 21:03:58 +00:00
}
2008-03-12 01:26:44 +00:00
2005-12-01 13:39:48 +00:00
descriptor - > lob_size = - 1 ;
descriptor - > lob_current_position = 0 ;
descriptor - > buffering = 0 ;
2001-09-11 21:03:58 +00:00
}
2005-12-01 13:39:48 +00:00
if ( column - > data_type ! = SQLT_RDD & & ( mode & PHP_OCI_RETURN_LOBS ) ) {
/* PHP_OCI_RETURN_LOBS means that we want the content of the LOB back instead of the locator */
2008-03-12 01:26:44 +00:00
2014-03-10 23:33:35 +00:00
if ( column - > chunk_size )
2015-01-03 09:22:58 +00:00
descriptor - > chunk_size = column - > chunk_size ;
2014-12-13 22:06:14 +00:00
lob_fetch_status = php_oci_lob_read ( descriptor , - 1 , 0 , & lob_buffer , & lob_length ) ;
2014-03-10 23:33:35 +00:00
if ( descriptor - > chunk_size ) /* Cache the chunk_size to avoid recalling OCILobGetChunkSize */
column - > chunk_size = descriptor - > chunk_size ;
2014-12-13 22:06:14 +00:00
php_oci_temp_lob_close ( descriptor ) ;
2008-01-15 20:44:31 +00:00
if ( lob_fetch_status ) {
2005-12-01 13:39:48 +00:00
ZVAL_FALSE ( value ) ;
return 1 ;
} else {
if ( lob_length > 0 ) {
2014-05-21 23:43:44 +00:00
ZVAL_STRINGL ( value , lob_buffer , lob_length ) ;
2006-08-15 13:08:34 +00:00
} else {
2005-12-01 13:39:48 +00:00
ZVAL_EMPTY_STRING ( value ) ;
2002-11-15 17:59:19 +00:00
}
2015-07-30 10:25:40 +00:00
if ( lob_buffer )
efree ( lob_buffer ) ;
2005-12-01 13:39:48 +00:00
return 0 ;
}
2008-02-16 01:20:22 +00:00
} else {
2005-12-01 13:39:48 +00:00
/* return the locator */
object_init_ex ( value , oci_lob_class_entry_ptr ) ;
add_property_resource ( value , " descriptor " , column - > descid ) ;
2018-09-24 10:05:54 +00:00
GC_ADDREF ( column - > descid ) ;
2005-12-01 13:39:48 +00:00
}
2006-08-15 13:08:34 +00:00
} else {
2005-12-01 13:39:48 +00:00
switch ( column - > retcode ) {
2008-02-16 01:20:22 +00:00
case 0 :
2005-12-01 13:39:48 +00:00
/* intact value */
if ( column - > piecewise ) {
column_size = column - > retlen4 ;
} else {
column_size = column - > retlen ;
2002-11-15 17:59:19 +00:00
}
break ;
2008-03-12 01:26:44 +00:00
default :
2008-02-16 01:20:22 +00:00
ZVAL_FALSE ( value ) ;
2005-12-01 13:39:48 +00:00
return 0 ;
2001-04-13 14:43:39 +00:00
}
2008-03-12 01:26:44 +00:00
2014-05-21 23:43:44 +00:00
ZVAL_STRINGL ( value , column - > data , column_size ) ;
2001-04-13 14:43:39 +00:00
}
2005-12-01 13:39:48 +00:00
return 0 ;
2001-04-13 14:43:39 +00:00
}
/* }}} */
2013-07-24 22:33:22 +00:00
2008-02-16 01:20:22 +00:00
/* {{{ php_oci_fetch_row()
2008-04-18 00:05:27 +00:00
*
* Fetch the next row from the given statement
2013-07-24 22:33:22 +00:00
* Has logic for Oracle 12 c Implicit Result Sets
2008-04-18 00:05:27 +00:00
*/
2005-12-01 13:39:48 +00:00
void php_oci_fetch_row ( INTERNAL_FUNCTION_PARAMETERS , int mode , int expected_args )
2001-04-13 14:43:39 +00:00
{
2005-12-01 13:39:48 +00:00
zval * z_statement , * array ;
2015-09-15 00:06:29 +00:00
zval * placeholder = ( zval * ) NULL ;
2015-09-11 23:10:32 +00:00
/* zend_array *temp_array = (zend_array *) NULL;*/
2013-07-24 22:33:22 +00:00
php_oci_statement * statement ; /* statement that will be fetched from */
# if (OCI_MAJOR_VERSION >= 12)
php_oci_statement * invokedstatement ; /* statement this function was invoked with */
# endif /* OCI_MAJOR_VERSION */
2005-12-01 13:39:48 +00:00
php_oci_out_column * column ;
ub4 nrows = 1 ;
int i ;
2014-09-09 11:12:26 +00:00
zend_long fetch_mode = 0 ;
2004-01-21 16:18:58 +00:00
2005-12-01 13:39:48 +00:00
if ( expected_args > 2 ) {
/* only for ocifetchinto BC */
2001-04-25 17:48:30 +00:00
2018-12-09 00:28:04 +00:00
ZEND_PARSE_PARAMETERS_START ( 2 , 3 )
Z_PARAM_RESOURCE ( z_statement )
Z_PARAM_ZVAL ( array )
Z_PARAM_OPTIONAL
Z_PARAM_LONG ( fetch_mode )
ZEND_PARSE_PARAMETERS_END ( ) ;
2008-03-12 01:26:44 +00:00
2005-12-01 13:39:48 +00:00
if ( ZEND_NUM_ARGS ( ) = = 2 ) {
fetch_mode = mode ;
2001-04-25 17:48:30 +00:00
}
2015-09-15 00:06:29 +00:00
if ( Z_ISREF_P ( array ) )
placeholder = Z_REFVAL_P ( array ) ;
else
placeholder = array ;
2006-08-15 13:08:34 +00:00
} else if ( expected_args = = 2 ) {
2005-12-01 13:39:48 +00:00
/* only for oci_fetch_array() */
2004-01-21 16:18:58 +00:00
2018-12-09 00:28:04 +00:00
ZEND_PARSE_PARAMETERS_START ( 1 , 2 )
Z_PARAM_RESOURCE ( z_statement )
Z_PARAM_OPTIONAL
Z_PARAM_LONG ( fetch_mode )
ZEND_PARSE_PARAMETERS_END ( ) ;
2008-03-12 01:26:44 +00:00
2005-12-01 13:39:48 +00:00
if ( ZEND_NUM_ARGS ( ) = = 1 ) {
fetch_mode = mode ;
2001-04-25 17:48:30 +00:00
}
2006-08-15 13:08:34 +00:00
} else {
2005-12-01 13:39:48 +00:00
/* for all oci_fetch_*() */
2008-03-12 01:26:44 +00:00
2018-12-09 00:28:04 +00:00
ZEND_PARSE_PARAMETERS_START ( 1 , 1 )
Z_PARAM_RESOURCE ( z_statement )
ZEND_PARSE_PARAMETERS_END ( ) ;
2008-03-12 01:26:44 +00:00
2005-12-01 13:39:48 +00:00
fetch_mode = mode ;
2001-04-13 14:43:39 +00:00
}
2004-01-21 16:18:58 +00:00
2006-05-18 13:21:08 +00:00
if ( ! ( fetch_mode & PHP_OCI_NUM ) & & ! ( fetch_mode & PHP_OCI_ASSOC ) ) {
/* none of the modes present, use the default one */
if ( mode & PHP_OCI_ASSOC ) {
fetch_mode | = PHP_OCI_ASSOC ;
2008-02-16 01:20:22 +00:00
}
2006-05-18 13:21:08 +00:00
if ( mode & PHP_OCI_NUM ) {
fetch_mode | = PHP_OCI_NUM ;
}
}
2013-07-24 22:33:22 +00:00
# if (OCI_MAJOR_VERSION < 12)
2005-12-01 13:39:48 +00:00
PHP_OCI_ZVAL_TO_STATEMENT ( z_statement , statement ) ;
2001-04-13 14:43:39 +00:00
2014-12-13 22:06:14 +00:00
if ( php_oci_statement_fetch ( statement , nrows ) ) {
2013-07-24 22:33:22 +00:00
RETURN_FALSE ; /* end of fetch */
2002-11-15 17:59:19 +00:00
}
2013-07-24 22:33:22 +00:00
# else /* OCI_MAJOR_VERSION */
PHP_OCI_ZVAL_TO_STATEMENT ( z_statement , invokedstatement ) ;
2016-08-04 04:48:07 +00:00
if ( invokedstatement - > impres_flag = = PHP_OCI_IMPRES_NO_CHILDREN | |
invokedstatement - > impres_flag = = PHP_OCI_IMPRES_IS_CHILD ) {
2013-07-24 22:33:22 +00:00
/* Already know there are no Implicit Result Sets */
2015-01-03 09:22:58 +00:00
statement = invokedstatement ;
2013-07-24 22:33:22 +00:00
} else if ( invokedstatement - > impres_flag = = PHP_OCI_IMPRES_HAS_CHILDREN ) {
/* Previously saw an Implicit Result Set in an earlier invocation of php_oci_fetch_row */
statement = ( php_oci_statement * ) invokedstatement - > impres_child_stmt ;
} else {
sword errstatus ;
2015-01-03 09:22:58 +00:00
2013-07-24 22:33:22 +00:00
/* Check for an Implicit Result Set on this statement handle */
2015-01-03 09:22:58 +00:00
PHP_OCI_CALL_RETURN ( errstatus , OCIAttrGet , ( ( dvoid * ) invokedstatement - > stmt , OCI_HTYPE_STMT ,
( dvoid * ) & invokedstatement - > impres_count ,
2013-07-24 22:33:22 +00:00
( ub4 * ) NULL , OCI_ATTR_IMPLICIT_RESULT_COUNT , invokedstatement - > err ) ) ;
if ( errstatus ) {
RETURN_FALSE ;
}
if ( invokedstatement - > impres_count > 0 ) {
/* Make it so the fetch occurs on the first Implicit Result Set */
2014-12-13 22:06:14 +00:00
statement = php_oci_get_implicit_resultset ( invokedstatement ) ;
if ( ! statement | | php_oci_statement_execute ( statement , ( ub4 ) OCI_DEFAULT ) )
2013-07-24 22:33:22 +00:00
RETURN_FALSE ;
invokedstatement - > impres_count - - ;
invokedstatement - > impres_child_stmt = ( struct php_oci_statement * ) statement ;
invokedstatement - > impres_flag = PHP_OCI_IMPRES_HAS_CHILDREN ;
} else {
statement = invokedstatement ; /* didn't find Implicit Result Sets */
invokedstatement - > impres_flag = PHP_OCI_IMPRES_NO_CHILDREN ; /* Don't bother checking again */
}
}
2014-12-13 22:06:14 +00:00
if ( php_oci_statement_fetch ( statement , nrows ) ) {
2013-07-24 22:33:22 +00:00
/* End of fetch */
if ( invokedstatement - > impres_count > 0 ) {
/* Check next Implicit Result Set */
2014-12-13 22:06:14 +00:00
statement = php_oci_get_implicit_resultset ( invokedstatement ) ;
if ( ! statement | | php_oci_statement_execute ( statement , ( ub4 ) OCI_DEFAULT ) )
2013-07-24 22:33:22 +00:00
RETURN_FALSE ;
2013-07-26 20:34:45 +00:00
invokedstatement - > impres_count - - ;
2013-07-24 22:33:22 +00:00
invokedstatement - > impres_child_stmt = ( struct php_oci_statement * ) statement ;
2014-12-13 22:06:14 +00:00
if ( php_oci_statement_fetch ( statement , nrows ) ) {
2013-07-24 22:33:22 +00:00
/* End of all fetches */
RETURN_FALSE ;
}
} else {
RETURN_FALSE ;
}
2021-06-29 08:04:10 +00:00
}
2013-07-24 22:33:22 +00:00
# endif /* OCI_MAJOR_VERSION */
2001-04-13 14:43:39 +00:00
2015-09-15 00:06:29 +00:00
if ( placeholder = = NULL ) {
2015-09-11 23:10:32 +00:00
placeholder = return_value ;
2015-09-15 00:06:29 +00:00
} else {
2017-09-20 13:46:04 +00:00
zval_ptr_dtor ( placeholder ) ;
2015-07-30 10:25:40 +00:00
}
2015-09-11 23:10:32 +00:00
array_init ( placeholder ) ;
2001-05-22 23:16:03 +00:00
2005-12-01 13:39:48 +00:00
for ( i = 0 ; i < statement - > ncolumns ; i + + ) {
2008-03-12 01:26:44 +00:00
2014-12-13 22:06:14 +00:00
column = php_oci_statement_get_column ( statement , i + 1 , NULL , 0 ) ;
2008-03-12 01:26:44 +00:00
2005-12-01 13:39:48 +00:00
if ( column = = NULL ) {
continue ;
}
if ( ( column - > indicator = = - 1 ) & & ( ( fetch_mode & PHP_OCI_RETURN_NULLS ) = = 0 ) ) {
continue ;
}
2001-04-13 14:43:39 +00:00
2005-12-01 13:39:48 +00:00
if ( ! ( column - > indicator = = - 1 ) ) {
2014-09-09 19:50:26 +00:00
zval element ;
2008-03-12 01:26:44 +00:00
2015-08-12 11:57:16 +00:00
php_oci_column_to_zval ( column , & element , ( int ) fetch_mode ) ;
2001-08-15 16:00:56 +00:00
2005-12-01 13:39:48 +00:00
if ( fetch_mode & PHP_OCI_NUM | | ! ( fetch_mode & PHP_OCI_ASSOC ) ) {
2015-09-11 23:10:32 +00:00
add_index_zval ( placeholder , i , & element ) ;
2005-12-01 13:39:48 +00:00
}
if ( fetch_mode & PHP_OCI_ASSOC ) {
if ( fetch_mode & PHP_OCI_NUM ) {
2015-07-16 03:06:35 +00:00
Z_TRY_ADDREF_P ( & element ) ;
2005-12-01 13:39:48 +00:00
}
2015-09-11 23:10:32 +00:00
add_assoc_zval ( placeholder , column - > name , & element ) ;
2005-12-01 13:39:48 +00:00
}
2008-03-12 01:26:44 +00:00
2005-12-01 13:39:48 +00:00
} else {
if ( fetch_mode & PHP_OCI_NUM | | ! ( fetch_mode & PHP_OCI_ASSOC ) ) {
2015-09-11 23:10:32 +00:00
add_index_null ( placeholder , i ) ;
2005-12-01 13:39:48 +00:00
}
if ( fetch_mode & PHP_OCI_ASSOC ) {
2015-09-11 23:10:32 +00:00
add_assoc_null ( placeholder , column - > name ) ;
2005-12-01 13:39:48 +00:00
}
}
2002-11-15 17:59:19 +00:00
}
2001-04-13 14:43:39 +00:00
2005-12-01 13:39:48 +00:00
if ( expected_args > 2 ) {
2014-08-25 17:24:55 +00:00
RETURN_LONG ( statement - > ncolumns ) ;
2002-11-15 17:59:19 +00:00
}
2005-12-01 13:39:48 +00:00
}
/* }}} */
2001-04-13 14:43:39 +00:00
2008-02-16 01:20:22 +00:00
/* {{{ php_oci_persistent_helper()
2008-04-18 00:05:27 +00:00
*
* Helper function to close / rollback persistent connections at the end of request . A return value of
* 1 indicates that the connection is to be destroyed
*/
2015-06-27 06:09:05 +00:00
static int php_oci_persistent_helper ( zval * zv )
2005-12-01 13:39:48 +00:00
{
2015-06-27 06:09:05 +00:00
zend_resource * le = Z_RES_P ( zv ) ;
2005-12-01 13:39:48 +00:00
time_t timestamp ;
php_oci_connection * connection ;
2001-04-13 14:43:39 +00:00
2005-12-01 13:39:48 +00:00
timestamp = time ( NULL ) ;
2008-03-12 01:26:44 +00:00
2008-04-18 00:05:27 +00:00
/* Persistent connection stubs are also counted as they have private session pools */
2005-12-01 13:39:48 +00:00
if ( le - > type = = le_pconnection ) {
connection = ( php_oci_connection * ) le - > ptr ;
2002-11-15 17:59:19 +00:00
2017-04-07 18:40:40 +00:00
/* Remove TAF callback function as it's bound to current request */
if ( connection - > used_this_request & & ! Z_ISUNDEF ( connection - > taf_callback ) & & ! Z_ISNULL ( connection - > taf_callback ) ) {
2017-07-26 05:22:44 +00:00
php_oci_unregister_taf_callback ( connection ) ;
2017-04-07 18:40:40 +00:00
}
2008-04-18 00:05:27 +00:00
if ( ! connection - > used_this_request & & OCI_G ( persistent_timeout ) ! = - 1 ) {
2013-08-31 00:37:44 +00:00
# ifdef HAVE_OCI8_DTRACE
2013-07-24 22:33:22 +00:00
if ( DTRACE_OCI8_CONNECT_EXPIRY_ENABLED ( ) ) {
2013-09-03 22:17:36 +00:00
DTRACE_OCI8_CONNECT_EXPIRY ( connection , connection - > is_stub ? 1 : 0 , ( long ) connection - > idle_expiry , ( long ) timestamp ) ;
2008-03-22 01:27:50 +00:00
}
2013-08-31 00:37:44 +00:00
# endif /* HAVE_OCI8_DTRACE */
2005-12-01 13:39:48 +00:00
if ( connection - > idle_expiry < timestamp ) {
/* connection has timed out */
2007-08-06 20:32:55 +00:00
return ZEND_HASH_APPLY_REMOVE ;
2002-11-15 17:59:19 +00:00
}
2005-12-01 13:39:48 +00:00
}
2001-04-25 17:48:30 +00:00
}
2007-08-06 20:32:55 +00:00
return ZEND_HASH_APPLY_KEEP ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2001-04-13 14:43:39 +00:00
2008-01-31 01:33:30 +00:00
/* {{{ php_oci_create_spool()
2008-04-18 00:05:27 +00:00
*
* Create ( alloc + Init ) Session pool for the given dbname and charsetid
*/
2014-12-13 22:06:14 +00:00
static php_oci_spool * php_oci_create_spool ( char * username , int username_len , char * password , int password_len , char * dbname , int dbname_len , zend_string * hash_key , int charsetid )
2008-01-31 01:33:30 +00:00
{
php_oci_spool * session_pool = NULL ;
2021-01-15 11:30:54 +00:00
bool iserror = 0 ;
2008-03-12 01:26:44 +00:00
ub4 poolmode = OCI_DEFAULT ; /* Mode to be passed to OCISessionPoolCreate */
2009-10-06 22:36:32 +00:00
OCIAuthInfo * spoolAuth = NULL ;
2013-09-06 01:18:29 +00:00
sword errstatus ;
2008-01-31 01:33:30 +00:00
2011-11-18 09:59:35 +00:00
/* Allocate sessionpool out of persistent memory */
2008-01-31 01:33:30 +00:00
session_pool = ( php_oci_spool * ) calloc ( 1 , sizeof ( php_oci_spool ) ) ;
2011-11-18 09:59:35 +00:00
if ( session_pool = = NULL ) {
iserror = 1 ;
goto exit_create_spool ;
}
2008-01-31 01:33:30 +00:00
2008-03-12 01:26:44 +00:00
/* Populate key if passed */
2015-11-15 21:15:22 +00:00
if ( hash_key & & ( ZSTR_LEN ( hash_key ) > 0 ) ) {
2014-08-25 17:24:55 +00:00
session_pool - > spool_hash_key = zend_string_dup ( hash_key , 1 ) ;
2011-11-18 09:59:35 +00:00
if ( session_pool - > spool_hash_key = = NULL ) {
iserror = 1 ;
goto exit_create_spool ;
}
2008-04-18 00:05:27 +00:00
}
2008-03-12 01:26:44 +00:00
2008-01-31 01:33:30 +00:00
/* Create the session pool's env */
2014-12-13 22:06:14 +00:00
if ( ! ( session_pool - > env = php_oci_create_env ( charsetid ) ) ) {
2008-01-31 01:33:30 +00:00
iserror = 1 ;
goto exit_create_spool ;
}
/* Allocate the pool handle */
2013-09-06 01:18:29 +00:00
PHP_OCI_CALL_RETURN ( errstatus , OCIHandleAlloc , ( session_pool - > env , ( dvoid * * ) & session_pool - > poolh , OCI_HTYPE_SPOOL , ( size_t ) 0 , ( dvoid * * ) 0 ) ) ;
2008-01-31 01:33:30 +00:00
2013-09-06 01:18:29 +00:00
if ( errstatus ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
OCI_G ( errcode ) = php_oci_error ( OCI_G ( err ) , errstatus ) ;
2008-01-31 01:33:30 +00:00
iserror = 1 ;
goto exit_create_spool ;
}
2008-04-18 00:05:27 +00:00
/* Allocate the session pool error handle - This only for use in the destructor, as there is a
* generic bug which can free up the OCI_G ( err ) variable before destroying connections . We
* cannot use this for other roundtrip calls as there is no way the user can access this error
2008-02-16 01:20:22 +00:00
*/
2013-09-06 01:18:29 +00:00
PHP_OCI_CALL_RETURN ( errstatus , OCIHandleAlloc , ( ( dvoid * ) session_pool - > env , ( dvoid * * ) & ( session_pool - > err ) , ( ub4 ) OCI_HTYPE_ERROR , ( size_t ) 0 , ( dvoid * * ) 0 ) ) ;
2008-01-31 01:33:30 +00:00
2013-09-06 01:18:29 +00:00
if ( errstatus ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
OCI_G ( errcode ) = php_oci_error ( OCI_G ( err ) , errstatus ) ;
2008-01-31 01:33:30 +00:00
iserror = 1 ;
goto exit_create_spool ;
2008-02-16 01:20:22 +00:00
}
2008-01-31 01:33:30 +00:00
2008-04-18 00:05:27 +00:00
/* Disable RLB as we mostly have single-connection pools */
2008-03-12 01:26:44 +00:00
poolmode = OCI_SPC_NO_RLB | OCI_SPC_HOMOGENEOUS ;
2013-07-24 22:33:22 +00:00
/* {{{ Allocate auth handle for session pool */
2013-09-06 01:18:29 +00:00
PHP_OCI_CALL_RETURN ( errstatus , OCIHandleAlloc , ( session_pool - > env , ( dvoid * * ) & ( spoolAuth ) , OCI_HTYPE_AUTHINFO , 0 , NULL ) ) ;
2009-10-06 22:36:32 +00:00
2013-09-06 01:18:29 +00:00
if ( errstatus ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
OCI_G ( errcode ) = php_oci_error ( OCI_G ( err ) , errstatus ) ;
2009-10-06 22:36:32 +00:00
iserror = 1 ;
goto exit_create_spool ;
2021-06-29 08:04:10 +00:00
}
2013-07-24 22:33:22 +00:00
/* }}} */
2009-10-06 22:36:32 +00:00
2013-07-24 22:33:22 +00:00
/* {{{ Set the edition attribute on the auth handle */
2009-10-06 22:36:32 +00:00
if ( OCI_G ( edition ) ) {
2013-09-06 01:18:29 +00:00
PHP_OCI_CALL_RETURN ( errstatus , OCIAttrSet , ( ( dvoid * ) spoolAuth , ( ub4 ) OCI_HTYPE_AUTHINFO , ( dvoid * ) OCI_G ( edition ) , ( ub4 ) ( strlen ( OCI_G ( edition ) ) ) , ( ub4 ) OCI_ATTR_EDITION , OCI_G ( err ) ) ) ;
2009-10-06 22:36:32 +00:00
2013-09-06 01:18:29 +00:00
if ( errstatus ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
OCI_G ( errcode ) = php_oci_error ( OCI_G ( err ) , errstatus ) ;
2009-10-06 22:36:32 +00:00
iserror = 1 ;
goto exit_create_spool ;
}
2013-07-24 22:33:22 +00:00
}
/* }}} */
2009-10-06 22:36:32 +00:00
2013-07-24 22:33:22 +00:00
/* {{{ Set the driver name attribute on the auth handle */
2013-09-06 01:18:29 +00:00
PHP_OCI_CALL_RETURN ( errstatus , OCIAttrSet , ( ( dvoid * ) spoolAuth , ( ub4 ) OCI_HTYPE_AUTHINFO , ( dvoid * ) PHP_OCI8_DRIVER_NAME , ( ub4 ) sizeof ( PHP_OCI8_DRIVER_NAME ) - 1 , ( ub4 ) OCI_ATTR_DRIVER_NAME , OCI_G ( err ) ) ) ;
2009-10-06 22:36:32 +00:00
2013-09-06 01:18:29 +00:00
if ( errstatus ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
OCI_G ( errcode ) = php_oci_error ( OCI_G ( err ) , errstatus ) ;
2009-10-06 22:36:32 +00:00
iserror = 1 ;
goto exit_create_spool ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2009-10-06 22:36:32 +00:00
2013-07-24 22:33:22 +00:00
/* {{{ Set the auth handle on the session pool */
2013-09-06 01:18:29 +00:00
PHP_OCI_CALL_RETURN ( errstatus , OCIAttrSet , ( ( dvoid * ) ( session_pool - > poolh ) , ( ub4 ) OCI_HTYPE_SPOOL , ( dvoid * ) spoolAuth , ( ub4 ) 0 , ( ub4 ) OCI_ATTR_SPOOL_AUTH , OCI_G ( err ) ) ) ;
2009-10-06 22:36:32 +00:00
2013-09-06 01:18:29 +00:00
if ( errstatus ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
OCI_G ( errcode ) = php_oci_error ( OCI_G ( err ) , errstatus ) ;
2009-10-06 22:36:32 +00:00
iserror = 1 ;
goto exit_create_spool ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2009-10-06 22:36:32 +00:00
2008-04-18 00:05:27 +00:00
/* Create the homogeneous session pool - We have different session pools for every different
* username , password , charset and dbname .
2008-02-16 01:20:22 +00:00
*/
2013-09-06 01:18:29 +00:00
PHP_OCI_CALL_RETURN ( errstatus , OCISessionPoolCreate , ( session_pool - > env , OCI_G ( err ) , session_pool - > poolh , ( OraText * * ) & session_pool - > poolname , & session_pool - > poolname_len , ( OraText * ) dbname , ( ub4 ) dbname_len , 0 , UB4MAXVAL , 1 , ( OraText * ) username , ( ub4 ) username_len , ( OraText * ) password , ( ub4 ) password_len , poolmode ) ) ;
2008-03-12 01:26:44 +00:00
2013-09-06 01:18:29 +00:00
if ( errstatus ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
OCI_G ( errcode ) = php_oci_error ( OCI_G ( err ) , errstatus ) ;
2008-01-31 01:33:30 +00:00
iserror = 1 ;
}
2008-03-12 01:26:44 +00:00
2008-01-31 01:33:30 +00:00
exit_create_spool :
if ( iserror & & session_pool ) {
2014-12-13 22:06:14 +00:00
php_oci_spool_close ( session_pool ) ;
2008-01-31 01:33:30 +00:00
session_pool = NULL ;
}
2009-10-06 22:36:32 +00:00
if ( spoolAuth ) {
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL ( OCIHandleFree , ( ( dvoid * ) spoolAuth , ( ub4 ) OCI_HTYPE_AUTHINFO ) ) ;
2009-10-06 22:36:32 +00:00
}
2013-08-31 00:37:44 +00:00
# ifdef HAVE_OCI8_DTRACE
2013-07-24 22:33:22 +00:00
if ( DTRACE_OCI8_SESSPOOL_CREATE_ENABLED ( ) ) {
DTRACE_OCI8_SESSPOOL_CREATE ( session_pool ) ;
2008-02-16 01:20:22 +00:00
}
2013-08-31 00:37:44 +00:00
# endif /* HAVE_OCI8_DTRACE */
2008-02-16 01:20:22 +00:00
2008-01-31 01:33:30 +00:00
return session_pool ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2008-01-31 01:33:30 +00:00
/* {{{ php_oci_get_spool()
2008-04-18 00:05:27 +00:00
*
* Get Session pool for the given dbname and charsetid from the persistent list . Function called for
* non - persistent connections .
*/
2014-12-13 22:06:14 +00:00
static php_oci_spool * php_oci_get_spool ( char * username , int username_len , char * password , int password_len , char * dbname , int dbname_len , int charsetid )
2008-01-31 01:33:30 +00:00
{
smart_str spool_hashed_details = { 0 } ;
php_oci_spool * session_pool = NULL ;
2014-05-21 23:43:44 +00:00
zend_resource * spool_out_le = NULL ;
2021-01-15 11:30:54 +00:00
bool iserror = 0 ;
2014-09-10 10:40:32 +00:00
zval * spool_out_zv = NULL ;
2008-03-12 01:26:44 +00:00
2013-07-24 22:33:22 +00:00
/* {{{ Create the spool hash key */
2008-03-12 01:26:44 +00:00
smart_str_appendl_ex ( & spool_hashed_details , " oci8spool*** " , sizeof ( " oci8spool*** " ) - 1 , 0 ) ;
2008-01-31 01:33:30 +00:00
smart_str_appendl_ex ( & spool_hashed_details , username , username_len , 0 ) ;
2008-03-12 01:26:44 +00:00
smart_str_appendl_ex ( & spool_hashed_details , " ** " , sizeof ( " ** " ) - 1 , 0 ) ;
2009-10-06 22:36:32 +00:00
/* Add edition attribute to the hash */
if ( OCI_G ( edition ) ) {
smart_str_appendl_ex ( & spool_hashed_details , OCI_G ( edition ) , strlen ( OCI_G ( edition ) ) , 0 ) ;
}
smart_str_appendl_ex ( & spool_hashed_details , " ** " , sizeof ( " ** " ) - 1 , 0 ) ;
2008-01-31 01:33:30 +00:00
if ( password_len ) {
2014-09-09 11:12:26 +00:00
zend_ulong password_hash ;
2020-05-15 08:13:38 +00:00
password_hash = zend_hash_func ( password , password_len ) ;
2008-01-31 01:33:30 +00:00
smart_str_append_unsigned_ex ( & spool_hashed_details , password_hash , 0 ) ;
}
2008-03-12 01:26:44 +00:00
smart_str_appendl_ex ( & spool_hashed_details , " ** " , sizeof ( " ** " ) - 1 , 0 ) ;
2008-01-31 01:33:30 +00:00
2008-04-18 00:05:27 +00:00
if ( dbname_len ) {
smart_str_appendl_ex ( & spool_hashed_details , dbname , dbname_len , 0 ) ;
}
2008-03-12 01:26:44 +00:00
smart_str_appendl_ex ( & spool_hashed_details , " ** " , sizeof ( " ** " ) - 1 , 0 ) ;
2008-01-31 01:33:30 +00:00
smart_str_append_unsigned_ex ( & spool_hashed_details , charsetid , 0 ) ;
2009-10-06 22:36:32 +00:00
/* Session Pool Hash Key : oci8spool***username**edition**hashedpassword**dbname**charset */
2008-01-31 01:33:30 +00:00
smart_str_0 ( & spool_hashed_details ) ;
2021-09-24 01:40:27 +00:00
zend_str_tolower ( ZSTR_VAL ( spool_hashed_details . s ) , ZSTR_LEN ( spool_hashed_details . s ) ) ;
2008-01-31 01:33:30 +00:00
/* }}} */
2014-09-10 10:40:32 +00:00
spool_out_zv = zend_hash_find ( & EG ( persistent_list ) , spool_hashed_details . s ) ;
if ( spool_out_zv ! = NULL ) {
spool_out_le = Z_RES_P ( spool_out_zv ) ;
}
if ( spool_out_le = = NULL ) {
2008-01-31 01:33:30 +00:00
2014-12-13 22:06:14 +00:00
session_pool = php_oci_create_spool ( username , username_len , password , password_len , dbname , dbname_len , spool_hashed_details . s , charsetid ) ;
2008-01-31 01:33:30 +00:00
2008-03-12 01:26:44 +00:00
if ( session_pool = = NULL ) {
2008-01-31 01:33:30 +00:00
iserror = 1 ;
2008-03-12 01:26:44 +00:00
goto exit_get_spool ;
}
2018-09-24 10:05:54 +00:00
zend_register_persistent_resource_ex ( session_pool - > spool_hash_key , session_pool , le_psessionpool ) ;
2008-03-12 01:26:44 +00:00
} else if ( spool_out_le - > type = = le_psessionpool & &
2022-03-31 14:27:58 +00:00
zend_string_equals ( ( ( php_oci_spool * ) ( spool_out_le - > ptr ) ) - > spool_hash_key , spool_hashed_details . s ) ) {
2008-01-31 01:33:30 +00:00
/* retrieve the cached session pool */
session_pool = ( php_oci_spool * ) ( spool_out_le - > ptr ) ;
}
exit_get_spool :
2014-09-19 20:16:01 +00:00
smart_str_free ( & spool_hashed_details ) ;
2008-01-31 01:33:30 +00:00
if ( iserror & & session_pool ) {
2014-12-13 22:06:14 +00:00
php_oci_spool_close ( session_pool ) ;
2008-01-31 01:33:30 +00:00
session_pool = NULL ;
}
return session_pool ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2008-01-31 01:33:30 +00:00
/* {{{ php_oci_create_env()
2008-04-18 00:05:27 +00:00
*
* Create the OCI environment choosing the correct function for the OCI version
*/
2014-12-13 22:06:14 +00:00
static OCIEnv * php_oci_create_env ( ub2 charsetid )
2008-01-31 01:33:30 +00:00
{
OCIEnv * retenv = NULL ;
2008-06-05 23:43:10 +00:00
/* create an environment using the character set id */
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIEnvNlsCreate , ( & retenv , OCI_G ( events ) ? PHP_OCI_INIT_MODE | OCI_EVENTS : PHP_OCI_INIT_MODE , 0 , NULL , NULL , NULL , 0 , NULL , charsetid , charsetid ) ) ;
2008-01-31 01:33:30 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
2011-11-07 20:10:41 +00:00
sb4 ora_error_code = 0 ;
2015-07-30 10:25:40 +00:00
text ora_msg_buf [ PHP_OCI_ERRBUF_LEN ] ; /* Use traditional smaller size: non-PL/SQL errors should fit and it keeps the stack smaller */
2011-11-07 20:10:41 +00:00
2008-01-31 01:33:30 +00:00
# ifdef HAVE_OCI_INSTANT_CLIENT
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " OCIEnvNlsCreate() failed. There is something wrong with your system - please check that " PHP_OCI8_LIB_PATH_MSG " includes the directory with Oracle Instant Client libraries " ) ;
2008-01-31 01:33:30 +00:00
# else
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " OCIEnvNlsCreate() failed. There is something wrong with your system - please check that ORACLE_HOME and " PHP_OCI8_LIB_PATH_MSG " are set and point to the right directories " ) ;
2008-01-31 01:33:30 +00:00
# endif
2011-11-07 20:10:41 +00:00
if ( retenv
2015-07-30 10:25:40 +00:00
& & OCIErrorGet ( retenv , ( ub4 ) 1 , NULL , & ora_error_code , ora_msg_buf , ( ub4 ) PHP_OCI_ERRBUF_LEN , ( ub4 ) OCI_HTYPE_ENV ) = = OCI_SUCCESS
2011-11-07 20:10:41 +00:00
& & * ora_msg_buf ) {
2014-12-13 22:06:14 +00:00
php_error_docref ( NULL , E_WARNING , " %s " , ora_msg_buf ) ;
2011-11-07 20:10:41 +00:00
}
2015-01-03 09:22:58 +00:00
2008-01-31 01:33:30 +00:00
return NULL ;
}
return retenv ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2008-01-31 01:33:30 +00:00
/* {{{ php_oci_old_create_session()
2008-04-18 00:05:27 +00:00
*
* This function is to be deprecated in future in favour of OCISessionGet which is used in
* php_oci_do_connect_ex
*/
2014-12-13 22:06:14 +00:00
static int php_oci_old_create_session ( php_oci_connection * connection , char * dbname , int dbname_len , char * username , int username_len , char * password , int password_len , char * new_password , int new_password_len , int session_mode )
2008-01-31 01:33:30 +00:00
{
2015-08-12 11:57:16 +00:00
ub4 statement_cache_size = 0 ;
if ( OCI_G ( statement_cache_size ) > 0 ) {
2015-08-19 00:42:53 +00:00
if ( OCI_G ( statement_cache_size ) > SB4MAXVAL )
statement_cache_size = ( ub4 ) SB4MAXVAL ;
2015-08-12 11:57:16 +00:00
else
statement_cache_size = ( ub4 ) OCI_G ( statement_cache_size ) ;
}
2008-06-05 23:43:10 +00:00
2008-01-31 01:33:30 +00:00
/* Create the OCI environment separate for each connection */
2014-12-13 22:06:14 +00:00
if ( ! ( connection - > env = php_oci_create_env ( connection - > charset ) ) ) {
2008-03-12 01:26:44 +00:00
return 1 ;
2008-01-31 01:33:30 +00:00
}
2013-07-24 22:33:22 +00:00
/* {{{ Allocate our server handle */
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIHandleAlloc , ( connection - > env , ( dvoid * * ) & ( connection - > server ) , OCI_HTYPE_SERVER , 0 , NULL ) ) ;
2008-03-12 01:26:44 +00:00
2008-01-31 01:33:30 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_oci_error ( OCI_G ( err ) , OCI_G ( errcode ) ) ;
2008-01-31 01:33:30 +00:00
return 1 ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2008-01-31 01:33:30 +00:00
2013-07-24 22:33:22 +00:00
/* {{{ Attach to the server */
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIServerAttach , ( connection - > server , OCI_G ( err ) , ( text * ) dbname , dbname_len , ( ub4 ) OCI_DEFAULT ) ) ;
2008-03-12 01:26:44 +00:00
2008-01-31 01:33:30 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_oci_error ( OCI_G ( err ) , OCI_G ( errcode ) ) ;
2008-01-31 01:33:30 +00:00
return 1 ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2008-01-31 01:33:30 +00:00
connection - > is_attached = 1 ;
2013-07-24 22:33:22 +00:00
/* {{{ Allocate our session handle */
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIHandleAlloc , ( connection - > env , ( dvoid * * ) & ( connection - > session ) , OCI_HTYPE_SESSION , 0 , NULL ) ) ;
2008-03-12 01:26:44 +00:00
2008-01-31 01:33:30 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_oci_error ( OCI_G ( err ) , OCI_G ( errcode ) ) ;
2008-01-31 01:33:30 +00:00
return 1 ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2008-01-31 01:33:30 +00:00
2013-07-24 22:33:22 +00:00
/* {{{ Allocate our private error-handle */
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIHandleAlloc , ( connection - > env , ( dvoid * * ) & ( connection - > err ) , OCI_HTYPE_ERROR , 0 , NULL ) ) ;
2008-01-31 01:33:30 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_oci_error ( OCI_G ( err ) , OCI_G ( errcode ) ) ;
2008-01-31 01:33:30 +00:00
return 1 ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2008-01-31 01:33:30 +00:00
2013-07-24 22:33:22 +00:00
/* {{{ Allocate our service-context */
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIHandleAlloc , ( connection - > env , ( dvoid * * ) & ( connection - > svc ) , OCI_HTYPE_SVCCTX , 0 , NULL ) ) ;
2008-01-31 01:33:30 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_oci_error ( OCI_G ( err ) , OCI_G ( errcode ) ) ;
2008-01-31 01:33:30 +00:00
return 1 ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2008-01-31 01:33:30 +00:00
2013-07-24 22:33:22 +00:00
/* {{{ Set the username */
2008-01-31 01:33:30 +00:00
if ( username ) {
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIAttrSet , ( ( dvoid * ) connection - > session , ( ub4 ) OCI_HTYPE_SESSION , ( dvoid * ) username , ( ub4 ) username_len , ( ub4 ) OCI_ATTR_USERNAME , OCI_G ( err ) ) ) ;
2008-03-12 01:26:44 +00:00
2008-01-31 01:33:30 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_oci_error ( OCI_G ( err ) , OCI_G ( errcode ) ) ;
2008-01-31 01:33:30 +00:00
return 1 ;
2008-02-16 01:20:22 +00:00
}
2013-07-24 22:33:22 +00:00
}
/* }}} */
2008-01-31 01:33:30 +00:00
2013-07-24 22:33:22 +00:00
/* {{{ Set the password */
2008-01-31 01:33:30 +00:00
if ( password ) {
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIAttrSet , ( ( dvoid * ) connection - > session , ( ub4 ) OCI_HTYPE_SESSION , ( dvoid * ) password , ( ub4 ) password_len , ( ub4 ) OCI_ATTR_PASSWORD , OCI_G ( err ) ) ) ;
2008-03-12 01:26:44 +00:00
2008-01-31 01:33:30 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_oci_error ( OCI_G ( err ) , OCI_G ( errcode ) ) ;
2008-01-31 01:33:30 +00:00
return 1 ;
2008-02-16 01:20:22 +00:00
}
2013-07-24 22:33:22 +00:00
}
/* }}} */
2008-01-31 01:33:30 +00:00
2013-07-24 22:33:22 +00:00
/* {{{ Set the edition attribute on the session handle */
2009-10-06 22:36:32 +00:00
if ( OCI_G ( edition ) ) {
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIAttrSet , ( ( dvoid * ) connection - > session , ( ub4 ) OCI_HTYPE_SESSION , ( dvoid * ) OCI_G ( edition ) , ( ub4 ) ( strlen ( OCI_G ( edition ) ) ) , ( ub4 ) OCI_ATTR_EDITION , OCI_G ( err ) ) ) ;
2009-10-06 22:36:32 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_oci_error ( OCI_G ( err ) , OCI_G ( errcode ) ) ;
2009-10-06 22:36:32 +00:00
return 1 ;
}
}
2013-07-24 22:33:22 +00:00
/* }}} */
2009-10-06 22:36:32 +00:00
2013-07-24 22:33:22 +00:00
/* {{{ Set the driver name attribute on the session handle */
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIAttrSet , ( ( dvoid * ) connection - > session , ( ub4 ) OCI_HTYPE_SESSION , ( dvoid * ) PHP_OCI8_DRIVER_NAME , ( ub4 ) sizeof ( PHP_OCI8_DRIVER_NAME ) - 1 , ( ub4 ) OCI_ATTR_DRIVER_NAME , OCI_G ( err ) ) ) ;
2009-10-06 22:36:32 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_oci_error ( OCI_G ( err ) , OCI_G ( errcode ) ) ;
2009-10-06 22:36:32 +00:00
return 1 ;
}
2013-07-24 22:33:22 +00:00
/* }}} */
2009-10-06 22:36:32 +00:00
2013-07-24 22:33:22 +00:00
/* {{{ Set the server handle in the service handle */
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIAttrSet , ( connection - > svc , OCI_HTYPE_SVCCTX , connection - > server , 0 , OCI_ATTR_SERVER , OCI_G ( err ) ) ) ;
2008-01-31 01:33:30 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_oci_error ( OCI_G ( err ) , OCI_G ( errcode ) ) ;
2008-01-31 01:33:30 +00:00
return 1 ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2008-01-31 01:33:30 +00:00
2013-07-24 22:33:22 +00:00
/* {{{ Set the authentication handle in the service handle */
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIAttrSet , ( connection - > svc , OCI_HTYPE_SVCCTX , connection - > session , 0 , OCI_ATTR_SESSION , OCI_G ( err ) ) ) ;
2008-01-31 01:33:30 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_oci_error ( OCI_G ( err ) , OCI_G ( errcode ) ) ;
2008-01-31 01:33:30 +00:00
return 1 ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2008-01-31 01:33:30 +00:00
if ( new_password ) {
2013-07-24 22:33:22 +00:00
/* {{{ Try to change password if new one was provided */
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIPasswordChange , ( connection - > svc , OCI_G ( err ) , ( text * ) username , username_len , ( text * ) password , password_len , ( text * ) new_password , new_password_len , OCI_AUTH ) ) ;
2008-01-31 01:33:30 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_oci_error ( OCI_G ( err ) , OCI_G ( errcode ) ) ;
2008-01-31 01:33:30 +00:00
return 1 ;
}
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIAttrGet , ( ( dvoid * ) connection - > svc , OCI_HTYPE_SVCCTX , ( dvoid * ) & ( connection - > session ) , ( ub4 * ) 0 , OCI_ATTR_SESSION , OCI_G ( err ) ) ) ;
2008-01-31 01:33:30 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_oci_error ( OCI_G ( err ) , OCI_G ( errcode ) ) ;
2008-01-31 01:33:30 +00:00
return 1 ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2008-01-31 01:33:30 +00:00
} else {
2013-07-24 22:33:22 +00:00
/* {{{ start the session */
MFH
1. Merged ARG_INFO patch (Felipe)
2. Allow empty username & password so Oracle can do non-password based
authentication, i.e. "External Authentication".
http://news.php.net/php.internals/37545
[DOC]
A new OCI_CRED_EXT flag can be passed as the "session_mode" parameter
to oci_connect(), oci_new_connect() and oci_pconnect().
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT);
This tells Oracle to do external or OS authentication, if configured
in the database.
OCI_CRED_EXT can only be used with username of "/" and a empty
password. Oci8.privileged_connection may be On or Off. OCI_CRED_EXT
is not supported on Windows for security reasons.
The new flag may be combined with the existing OCI_SYSOPER or
OCI_SYSDBA modes (note: oci8.privileged_connection needs to be On for
OCI_SYSDBA and OCI_SYSOPER), e.g.:
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT+OCI_SYSOPER);
2008-07-16 22:16:03 +00:00
ub4 cred_type = OCI_CRED_RDBMS ;
/* Extract the overloaded session_mode parameter into valid Oracle credential and session mode values */
if ( session_mode & PHP_OCI_CRED_EXT ) {
cred_type = OCI_CRED_EXT ;
session_mode ^ = PHP_OCI_CRED_EXT ;
2008-01-31 01:33:30 +00:00
}
MFH
1. Merged ARG_INFO patch (Felipe)
2. Allow empty username & password so Oracle can do non-password based
authentication, i.e. "External Authentication".
http://news.php.net/php.internals/37545
[DOC]
A new OCI_CRED_EXT flag can be passed as the "session_mode" parameter
to oci_connect(), oci_new_connect() and oci_pconnect().
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT);
This tells Oracle to do external or OS authentication, if configured
in the database.
OCI_CRED_EXT can only be used with username of "/" and a empty
password. Oci8.privileged_connection may be On or Off. OCI_CRED_EXT
is not supported on Windows for security reasons.
The new flag may be combined with the existing OCI_SYSOPER or
OCI_SYSDBA modes (note: oci8.privileged_connection needs to be On for
OCI_SYSDBA and OCI_SYSOPER), e.g.:
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT+OCI_SYSOPER);
2008-07-16 22:16:03 +00:00
session_mode | = OCI_STMT_CACHE ;
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCISessionBegin , ( connection - > svc , OCI_G ( err ) , connection - > session , ( ub4 ) cred_type , ( ub4 ) session_mode ) ) ;
MFH
1. Merged ARG_INFO patch (Felipe)
2. Allow empty username & password so Oracle can do non-password based
authentication, i.e. "External Authentication".
http://news.php.net/php.internals/37545
[DOC]
A new OCI_CRED_EXT flag can be passed as the "session_mode" parameter
to oci_connect(), oci_new_connect() and oci_pconnect().
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT);
This tells Oracle to do external or OS authentication, if configured
in the database.
OCI_CRED_EXT can only be used with username of "/" and a empty
password. Oci8.privileged_connection may be On or Off. OCI_CRED_EXT
is not supported on Windows for security reasons.
The new flag may be combined with the existing OCI_SYSOPER or
OCI_SYSDBA modes (note: oci8.privileged_connection needs to be On for
OCI_SYSDBA and OCI_SYSOPER), e.g.:
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT+OCI_SYSOPER);
2008-07-16 22:16:03 +00:00
2008-01-31 01:33:30 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_oci_error ( OCI_G ( err ) , OCI_G ( errcode ) ) ;
2008-01-31 01:33:30 +00:00
/* OCISessionBegin returns OCI_SUCCESS_WITH_INFO when
* user ' s password has expired , but is still usable .
2008-03-12 01:26:44 +00:00
*/
2008-01-31 01:33:30 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS_WITH_INFO ) {
return 1 ;
}
2013-07-24 22:33:22 +00:00
}
/* }}} */
2008-01-31 01:33:30 +00:00
}
2008-03-12 01:26:44 +00:00
/* Brand new connection: Init and update the next_ping in the connection */
2014-12-13 22:06:14 +00:00
if ( php_oci_ping_init ( connection , OCI_G ( err ) ) ! = OCI_SUCCESS ) {
php_oci_error ( OCI_G ( err ) , OCI_G ( errcode ) ) ;
2008-03-12 01:26:44 +00:00
return 1 ;
}
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIAttrSet , ( ( dvoid * ) connection - > svc , ( ub4 ) OCI_HTYPE_SVCCTX , ( ub4 * ) & statement_cache_size , 0 , ( ub4 ) OCI_ATTR_STMTCACHESIZE , OCI_G ( err ) ) ) ;
2008-03-12 01:26:44 +00:00
2008-06-05 23:43:10 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_oci_error ( OCI_G ( err ) , OCI_G ( errcode ) ) ;
2008-06-05 23:43:10 +00:00
return 1 ;
2008-01-31 01:33:30 +00:00
}
2008-03-12 01:26:44 +00:00
/* Successfully created session */
2008-01-31 01:33:30 +00:00
return 0 ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2008-01-31 01:33:30 +00:00
/* {{{ php_oci_create_session()
2008-04-18 00:05:27 +00:00
*
* Create session using client - side session pool - new norm
*/
2014-12-13 22:06:14 +00:00
static int php_oci_create_session ( php_oci_connection * connection , php_oci_spool * session_pool , char * dbname , int dbname_len , char * username , int username_len , char * password , int password_len , char * new_password , int new_password_len , int session_mode )
2008-01-31 01:33:30 +00:00
{
php_oci_spool * actual_spool = NULL ;
ub4 purity = - 2 ; /* Illegal value to initialize */
2008-03-12 01:26:44 +00:00
time_t timestamp = time ( NULL ) ;
2015-08-12 11:57:16 +00:00
ub4 statement_cache_size = 0 ;
if ( OCI_G ( statement_cache_size ) > 0 ) {
2015-08-19 00:42:53 +00:00
if ( OCI_G ( statement_cache_size ) > SB4MAXVAL )
statement_cache_size = ( ub4 ) SB4MAXVAL ;
2015-08-12 11:57:16 +00:00
else
statement_cache_size = ( ub4 ) OCI_G ( statement_cache_size ) ;
}
2008-01-31 01:33:30 +00:00
/* Persistent connections have private session pools */
if ( connection - > is_persistent & & ! connection - > private_spool & &
2014-12-13 22:06:14 +00:00
! ( connection - > private_spool = php_oci_create_spool ( username , username_len , password , password_len , dbname , dbname_len , NULL , connection - > charset ) ) ) {
2008-01-31 01:33:30 +00:00
return 1 ;
}
actual_spool = ( connection - > is_persistent ) ? ( connection - > private_spool ) : ( session_pool ) ;
connection - > env = actual_spool - > env ;
2008-04-18 00:05:27 +00:00
/* Do this upfront so that connection close on an error would know that this is a session pool
* connection . Failure to do this would result in crashes in error scenarios
*/
2008-02-16 01:20:22 +00:00
if ( ! connection - > using_spool ) {
2008-01-31 01:33:30 +00:00
connection - > using_spool = 1 ;
}
2013-08-31 00:37:44 +00:00
# ifdef HAVE_OCI8_DTRACE
2013-07-24 22:33:22 +00:00
if ( DTRACE_OCI8_SESSPOOL_TYPE_ENABLED ( ) ) {
DTRACE_OCI8_SESSPOOL_TYPE ( session_pool ? 1 : 0 , session_pool ? session_pool : connection - > private_spool ) ;
2008-02-16 01:20:22 +00:00
}
2013-08-31 00:37:44 +00:00
# endif /* HAVE_OCI8_DTRACE */
2008-02-16 01:20:22 +00:00
2008-04-18 00:05:27 +00:00
/* The passed in "connection" can be a cached stub from plist or freshly created. In the former
* case , we do not have to allocate any handles
*/
2008-01-31 01:33:30 +00:00
2008-02-16 01:20:22 +00:00
if ( ! connection - > err ) {
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIHandleAlloc , ( connection - > env , ( dvoid * * ) & ( connection - > err ) , OCI_HTYPE_ERROR , 0 , NULL ) ) ;
2008-03-12 01:26:44 +00:00
2008-01-31 01:33:30 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_oci_error ( OCI_G ( err ) , OCI_G ( errcode ) ) ;
2008-01-31 01:33:30 +00:00
return 1 ;
}
}
/* {{{ Allocate and initialize the connection-private authinfo handle if not allocated yet */
2008-02-16 01:20:22 +00:00
if ( ! connection - > authinfo ) {
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIHandleAlloc , ( connection - > env , ( dvoid * * ) & ( connection - > authinfo ) , OCI_HTYPE_AUTHINFO , 0 , NULL ) ) ;
2008-01-31 01:33:30 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_oci_error ( OCI_G ( err ) , OCI_G ( errcode ) ) ;
2008-01-31 01:33:30 +00:00
return 1 ;
}
2008-03-12 01:26:44 +00:00
/* Set the Connection class and purity if OCI client version >= 11g */
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIAttrSet , ( ( dvoid * ) connection - > authinfo , ( ub4 ) OCI_HTYPE_SESSION , ( dvoid * ) OCI_G ( connection_class ) , ( ub4 ) ( strlen ( OCI_G ( connection_class ) ) ) , ( ub4 ) OCI_ATTR_CONNECTION_CLASS , OCI_G ( err ) ) ) ;
2008-01-31 01:33:30 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_oci_error ( OCI_G ( err ) , OCI_G ( errcode ) ) ;
2008-01-31 01:33:30 +00:00
return 1 ;
}
if ( connection - > is_persistent )
purity = OCI_ATTR_PURITY_SELF ;
else
purity = OCI_ATTR_PURITY_NEW ;
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIAttrSet , ( ( dvoid * ) connection - > authinfo , ( ub4 ) OCI_HTYPE_AUTHINFO , ( dvoid * ) & purity , ( ub4 ) 0 , ( ub4 ) OCI_ATTR_PURITY , OCI_G ( err ) ) ) ;
2008-01-31 01:33:30 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_oci_error ( OCI_G ( err ) , OCI_G ( errcode ) ) ;
2008-01-31 01:33:30 +00:00
return 1 ;
}
2013-07-24 22:33:22 +00:00
}
/* }}} */
2008-01-31 01:33:30 +00:00
2013-07-24 22:33:22 +00:00
/* {{{ Debug statements */
2013-08-31 00:37:44 +00:00
# ifdef HAVE_OCI8_DTRACE
2013-07-24 22:33:22 +00:00
if ( DTRACE_OCI8_SESSPOOL_STATS_ENABLED ( ) ) {
2008-03-12 01:26:44 +00:00
ub4 numfree = 0 , numbusy = 0 , numopen = 0 ;
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIAttrGet , ( ( dvoid * ) actual_spool - > poolh , OCI_HTYPE_SPOOL , ( dvoid * ) & numopen , ( ub4 * ) 0 , OCI_ATTR_SPOOL_OPEN_COUNT , OCI_G ( err ) ) ) ;
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIAttrGet , ( ( dvoid * ) actual_spool - > poolh , OCI_HTYPE_SPOOL , ( dvoid * ) & numbusy , ( ub4 * ) 0 , OCI_ATTR_SPOOL_BUSY_COUNT , OCI_G ( err ) ) ) ;
2008-03-12 01:26:44 +00:00
numfree = numopen - numbusy ; /* number of free connections in the pool */
2013-07-24 22:33:22 +00:00
DTRACE_OCI8_SESSPOOL_STATS ( numfree , numbusy , numopen ) ;
}
2013-08-31 00:37:44 +00:00
# endif /* HAVE_OCI8_DTRACE */
2013-07-24 22:33:22 +00:00
/* }}} */
2008-01-31 01:33:30 +00:00
2008-04-18 00:05:27 +00:00
/* Ping loop: Ping and loop till we get a good connection. When a database instance goes
* down , it can leave several bad connections that need to be flushed out before getting a
* good one . In non - RAC , we always get a brand new connection at the end of the loop and in
* RAC , we can get a good connection from a different instance before flushing out all bad
* ones . We do not need to ping brand new connections .
2008-03-12 01:26:44 +00:00
*/
do {
/* Continue to use the global error handle as the connection is closed when an error occurs */
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCISessionGet , ( connection - > env , OCI_G ( err ) , & ( connection - > svc ) , ( OCIAuthInfo * ) connection - > authinfo , ( OraText * ) actual_spool - > poolname , ( ub4 ) actual_spool - > poolname_len , NULL , 0 , NULL , NULL , NULL , OCI_SESSGET_SPOOL ) ) ;
2008-03-12 01:26:44 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_oci_error ( OCI_G ( err ) , OCI_G ( errcode ) ) ;
2008-03-12 01:26:44 +00:00
2008-04-18 00:05:27 +00:00
/* Session creation returns OCI_SUCCESS_WITH_INFO when user's password has expired, but
* is still usable .
2008-03-12 01:26:44 +00:00
*/
2008-01-31 01:33:30 +00:00
2008-03-12 01:26:44 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS_WITH_INFO ) {
return 1 ;
}
}
/* {{{ Populate the session and server fields of the connection */
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIAttrGet , ( ( dvoid * ) connection - > svc , OCI_HTYPE_SVCCTX , ( dvoid * ) & ( connection - > server ) , ( ub4 * ) 0 , OCI_ATTR_SERVER , OCI_G ( err ) ) ) ;
2008-03-12 01:26:44 +00:00
2015-01-03 09:22:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIAttrGet , ( ( dvoid * ) connection - > svc , OCI_HTYPE_SVCCTX , ( dvoid * ) & ( connection - > session ) , ( ub4 * ) 0 , OCI_ATTR_SESSION , OCI_G ( err ) ) ) ;
2013-07-24 22:33:22 +00:00
/* }}} */
2008-03-12 01:26:44 +00:00
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIContextGetValue , ( connection - > session , OCI_G ( err ) , ( ub1 * ) " NEXT_PING " , ( ub1 ) sizeof ( " NEXT_PING " ) , ( void * * ) & ( connection - > next_pingp ) ) ) ;
2008-03-12 01:26:44 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_oci_error ( OCI_G ( err ) , OCI_G ( errcode ) ) ;
2008-01-31 01:33:30 +00:00
return 1 ;
}
2008-03-12 01:26:44 +00:00
if ( ! ( connection - > next_pingp ) ) {
/* This is a brand new connection, we need not ping, but have to initialize ping */
2014-12-13 22:06:14 +00:00
if ( php_oci_ping_init ( connection , OCI_G ( err ) ) ! = OCI_SUCCESS ) {
php_oci_error ( OCI_G ( err ) , OCI_G ( errcode ) ) ;
2008-03-12 01:26:44 +00:00
return 1 ;
}
} else if ( ( * ( connection - > next_pingp ) > 0 ) & & ( timestamp > = * ( connection - > next_pingp ) ) ) {
2014-12-13 22:06:14 +00:00
if ( php_oci_connection_ping ( connection ) ) {
2008-03-12 01:26:44 +00:00
/* Got a good connection - update next_ping and get out of ping loop */
* ( connection - > next_pingp ) = timestamp + OCI_G ( ping_interval ) ;
} else {
/* Bad connection - remove from pool */
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL ( OCISessionRelease , ( connection - > svc , connection - > err , NULL , 0 , ( ub4 ) OCI_SESSRLS_DROPSESS ) ) ;
2008-03-12 01:26:44 +00:00
connection - > svc = NULL ;
connection - > server = NULL ;
connection - > session = NULL ;
}
} /* If ping applicable */
} while ( ! ( connection - > svc ) ) ;
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIAttrSet , ( ( dvoid * ) connection - > svc , ( ub4 ) OCI_HTYPE_SVCCTX , ( ub4 * ) & statement_cache_size , 0 , ( ub4 ) OCI_ATTR_STMTCACHESIZE , OCI_G ( err ) ) ) ;
MFH
1. Merged ARG_INFO patch (Felipe)
2. Allow empty username & password so Oracle can do non-password based
authentication, i.e. "External Authentication".
http://news.php.net/php.internals/37545
[DOC]
A new OCI_CRED_EXT flag can be passed as the "session_mode" parameter
to oci_connect(), oci_new_connect() and oci_pconnect().
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT);
This tells Oracle to do external or OS authentication, if configured
in the database.
OCI_CRED_EXT can only be used with username of "/" and a empty
password. Oci8.privileged_connection may be On or Off. OCI_CRED_EXT
is not supported on Windows for security reasons.
The new flag may be combined with the existing OCI_SYSOPER or
OCI_SYSDBA modes (note: oci8.privileged_connection needs to be On for
OCI_SYSDBA and OCI_SYSOPER), e.g.:
$c1 = oci_connect("/", "", $db, null, OCI_CRED_EXT+OCI_SYSOPER);
2008-07-16 22:16:03 +00:00
2008-06-05 23:43:10 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
2014-12-13 22:06:14 +00:00
php_oci_error ( OCI_G ( err ) , OCI_G ( errcode ) ) ;
2008-06-05 23:43:10 +00:00
return 1 ;
2008-01-31 01:33:30 +00:00
}
2008-02-16 01:20:22 +00:00
/* Session is now taken from the session pool and attached and open */
2008-01-31 01:33:30 +00:00
connection - > is_stub = 0 ;
2008-02-16 01:20:22 +00:00
connection - > is_attached = connection - > is_open = 1 ;
2008-01-31 01:33:30 +00:00
return 0 ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2008-01-31 01:33:30 +00:00
/* {{{ php_oci_spool_list_dtor()
2008-04-18 00:05:27 +00:00
*
* Session pool destructor function
*/
2014-12-13 22:06:14 +00:00
static void php_oci_spool_list_dtor ( zend_resource * entry )
2008-01-31 01:33:30 +00:00
{
php_oci_spool * session_pool = ( php_oci_spool * ) entry - > ptr ;
if ( session_pool ) {
2014-12-13 22:06:14 +00:00
php_oci_spool_close ( session_pool ) ;
2008-01-31 01:33:30 +00:00
}
return ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2008-01-31 01:33:30 +00:00
2008-03-12 01:26:44 +00:00
/* {{{ php_oci_spool_close()
2008-04-18 00:05:27 +00:00
*
* Destroys the OCI Session Pool
*/
2014-12-13 22:06:14 +00:00
static void php_oci_spool_close ( php_oci_spool * session_pool )
2008-01-31 01:33:30 +00:00
{
2008-02-16 01:20:22 +00:00
if ( session_pool - > poolname_len ) {
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL ( OCISessionPoolDestroy , ( ( dvoid * ) session_pool - > poolh ,
2008-02-16 01:20:22 +00:00
( dvoid * ) session_pool - > err , OCI_SPD_FORCE ) ) ;
2008-01-31 01:33:30 +00:00
}
2008-02-16 01:20:22 +00:00
if ( session_pool - > poolh ) {
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL ( OCIHandleFree , ( ( dvoid * ) session_pool - > poolh , OCI_HTYPE_SPOOL ) ) ;
2008-01-31 01:33:30 +00:00
}
2008-02-16 01:20:22 +00:00
if ( session_pool - > err ) {
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL ( OCIHandleFree , ( ( dvoid * ) session_pool - > err , OCI_HTYPE_ERROR ) ) ;
2008-01-31 01:33:30 +00:00
}
2008-02-16 01:20:22 +00:00
if ( session_pool - > env ) {
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL ( OCIHandleFree , ( ( dvoid * ) session_pool - > env , OCI_HTYPE_ENV ) ) ;
2008-01-31 01:33:30 +00:00
}
2008-02-16 01:20:22 +00:00
if ( session_pool - > spool_hash_key ) {
free ( session_pool - > spool_hash_key ) ;
2008-01-31 01:33:30 +00:00
}
free ( session_pool ) ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2008-01-31 01:33:30 +00:00
2008-03-12 01:26:44 +00:00
/* {{{ php_oci_ping_init()
2008-04-18 00:05:27 +00:00
*
* Initializes the next_ping time as a context value in the connection . We now use
* OCIContext { Get , Set } Value to store the next_ping because we need to support ping for
* non - persistent DRCP connections
*/
2014-12-13 22:06:14 +00:00
static sword php_oci_ping_init ( php_oci_connection * connection , OCIError * errh )
2008-03-12 01:26:44 +00:00
{
time_t * next_pingp = NULL ;
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIContextGetValue , ( connection - > session , errh , ( ub1 * ) " NEXT_PING " , ( ub1 ) sizeof ( " NEXT_PING " ) , ( void * * ) & next_pingp ) ) ;
2008-03-12 01:26:44 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
return OCI_G ( errcode ) ;
}
/* This must be a brand-new connection. Allocate memory for the ping */
if ( ! next_pingp ) {
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIMemoryAlloc , ( connection - > session , errh , ( void * * ) & next_pingp , OCI_DURATION_SESSION , sizeof ( time_t ) , OCI_MEMORY_CLEARED ) ) ;
2008-03-12 01:26:44 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
return OCI_G ( errcode ) ;
}
}
if ( OCI_G ( ping_interval ) > = 0 ) {
time_t timestamp = time ( NULL ) ;
* next_pingp = timestamp + OCI_G ( ping_interval ) ;
} else {
* next_pingp = 0 ;
}
/* Set the new ping value into the connection */
2013-08-26 21:20:58 +00:00
PHP_OCI_CALL_RETURN ( OCI_G ( errcode ) , OCIContextSetValue , ( connection - > session , errh , OCI_DURATION_SESSION , ( ub1 * ) " NEXT_PING " , ( ub1 ) sizeof ( " NEXT_PING " ) , next_pingp ) ) ;
2008-03-12 01:26:44 +00:00
if ( OCI_G ( errcode ) ! = OCI_SUCCESS ) {
OCIMemoryFree ( connection - > session , errh , next_pingp ) ;
return OCI_G ( errcode ) ;
}
/* Cache the pointer so we do not have to do OCIContextGetValue repeatedly */
connection - > next_pingp = next_pingp ;
return OCI_SUCCESS ;
2013-07-24 22:33:22 +00:00
}
/* }}} */
2008-03-12 01:26:44 +00:00
2013-08-27 23:41:02 +00:00
/* {{{ php_oci_dtrace_check_connection()
*
* DTrace output for connections that may have become invalid and marked for reopening
*/
2013-09-06 01:18:29 +00:00
void php_oci_dtrace_check_connection ( php_oci_connection * connection , sb4 errcode , ub4 serverStatus )
2013-08-27 23:41:02 +00:00
{
2013-08-31 00:37:44 +00:00
# ifdef HAVE_OCI8_DTRACE
2013-08-27 23:41:02 +00:00
if ( DTRACE_OCI8_CHECK_CONNECTION_ENABLED ( ) ) {
2013-09-27 04:12:11 +00:00
DTRACE_OCI8_CHECK_CONNECTION ( connection , connection - > client_id , connection - > is_open ? 1 : 0 , ( long ) errcode , ( unsigned long ) serverStatus ) ;
2013-08-27 23:41:02 +00:00
}
2013-08-31 00:37:44 +00:00
# endif /* HAVE_OCI8_DTRACE */
2013-08-27 23:41:02 +00:00
}
/* }}} */
1999-04-21 22:49:16 +00:00
# endif /* HAVE_OCI8 */