Exemplo n.º 1
1
 protected function connect(&$username, &$password, &$driver_options)
 {
     $dbname = isset($this->dsn['dbname']) ? $this->dsn['dbname'] : '';
     $charset = isset($this->dsn['charset']) ? $this->dsn['charset'] : (isset($_ENV['NLS_LANG']) ? $_ENV['NLS_LANG'] : 'WE8ISO8859P1');
     ob_start();
     if (isset($driver_options[PDO::ATTR_PERSISTENT]) && $driver_options[PDO::ATTR_PERSISTENT]) {
         $this->link = oci_pconnect($username, $password, $dbname, $charset);
     } else {
         $this->link = oci_new_connect($username, $password, $dbname, $charset);
     }
     $error = ob_get_contents();
     ob_end_clean();
     if (!$this->link) {
         $this->set_driver_error(null, PDO::ERRMODE_EXCEPTION, '__construct');
     } else {
         if ($error) {
             $this->set_error(0, $this->clear_warning($error), 'HY000', PDO::ERRMODE_EXCEPTION, '__construct');
         }
     }
 }
Exemplo n.º 2
1
Arquivo: Oci8.php Projeto: orno/db
 /**
  * {@inheritdoc}
  *
  * @throws \Orno\Db\Exception\ConnectionException
  * @param  array $config
  * @return \Orno\Db\Driver\Oci8
  */
 public function connect(array $config = [])
 {
     if (is_resource($this->connection)) {
         return $this;
     }
     // filter config array
     $persistent = isset($config['persistent']) ? (bool) $config['persistent'] : true;
     $database = isset($config['database']) ? $config['database'] : $this->config['database'];
     $username = isset($config['username']) ? $config['username'] : $this->config['username'];
     $password = isset($config['password']) ? $config['password'] : $this->config['password'];
     $charset = isset($config['charset']) ? $config['charset'] : 'AL32UTF8';
     // intentionally supress errors to catch with oci_error
     $this->connection = $persistent === true ? @oci_pconnect($username, $password, $database, $charset) : @oci_new_connect($username, $password, $database, $charset);
     if (!$this->connection) {
         $e = oci_error();
         throw new Exception\ConnectionException($e['message'], $e['code']);
     }
     return $this;
 }
Exemplo n.º 3
1
 /**
  * Usually aborts on failure
  */
 function open($server, $user, $password, $dbName)
 {
     if (!function_exists('oci_connect')) {
         throw new DBConnectionError($this, "Oracle functions missing, have you compiled PHP with the --with-oci8 option?\n (Note: if you recently installed PHP, you may need to restart your webserver and database)\n");
     }
     $this->close();
     $this->mUser = $user;
     $this->mPassword = $password;
     // changed internal variables functions
     // mServer now holds the TNS endpoint
     // mDBname is schema name if different from username
     if (!$server) {
         // backward compatibillity (server used to be null and TNS was supplied in dbname)
         $this->mServer = $dbName;
         $this->mDBname = $user;
     } else {
         $this->mServer = $server;
         if (!$dbName) {
             $this->mDBname = $user;
         } else {
             $this->mDBname = $dbName;
         }
     }
     if (!strlen($user)) {
         # e.g. the class is being loaded
         return;
     }
     $session_mode = $this->mFlags & DBO_SYSDBA ? OCI_SYSDBA : OCI_DEFAULT;
     wfSuppressWarnings();
     if ($this->mFlags & DBO_DEFAULT) {
         $this->mConn = oci_new_connect($this->mUser, $this->mPassword, $this->mServer, $this->defaultCharset, $session_mode);
     } else {
         $this->mConn = oci_connect($this->mUser, $this->mPassword, $this->mServer, $this->defaultCharset, $session_mode);
     }
     wfRestoreWarnings();
     if ($this->mUser != $this->mDBname) {
         //change current schema in session
         $this->selectDB($this->mDBname);
     }
     if (!$this->mConn) {
         throw new DBConnectionError($this, $this->lastError());
     }
     $this->mOpened = true;
     # removed putenv calls because they interfere with the system globaly
     $this->doQuery('ALTER SESSION SET NLS_TIMESTAMP_FORMAT=\'DD-MM-YYYY HH24:MI:SS.FF6\'');
     $this->doQuery('ALTER SESSION SET NLS_TIMESTAMP_TZ_FORMAT=\'DD-MM-YYYY HH24:MI:SS.FF6\'');
     $this->doQuery('ALTER SESSION SET NLS_NUMERIC_CHARACTERS=\'.,\'');
     return $this->mConn;
 }
Exemplo n.º 4
1
 /**
  * Connect to db
  * Must be called before other methods.
  * @param string $dbhost The database host.
  * @param string $dbuser The database username.
  * @param string $dbpass The database username's password.
  * @param string $dbname The name of the database being connected to.
  * @param mixed $prefix string means moodle db prefix, false used for external databases where prefix not used
  * @param array $dboptions driver specific options
  * @return bool true
  * @throws dml_connection_exception if error
  */
 public function connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions = null)
 {
     if ($prefix == '' and !$this->external) {
         //Enforce prefixes for everybody but mysql
         throw new dml_exception('prefixcannotbeempty', $this->get_dbfamily());
     }
     if (!$this->external and strlen($prefix) > 2) {
         //Max prefix length for Oracle is 2cc
         $a = (object) array('dbfamily' => 'oracle', 'maxlength' => 2);
         throw new dml_exception('prefixtoolong', $a);
     }
     $driverstatus = $this->driver_installed();
     if ($driverstatus !== true) {
         throw new dml_exception('dbdriverproblem', $driverstatus);
     }
     // Autocommit ON by default.
     // Switching to OFF (OCI_DEFAULT), when playing with transactions
     // please note this thing is not defined if oracle driver not present in PHP
     // which means it can not be used as default value of object property!
     $this->commit_status = OCI_COMMIT_ON_SUCCESS;
     $this->store_settings($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions);
     unset($this->dboptions['dbsocket']);
     // NOTE: use of ', ", / and \ is very problematic, even native oracle tools seem to have
     //       problems with these, so just forget them and do not report problems into tracker...
     if (empty($this->dbhost)) {
         // old style full address (TNS)
         $dbstring = $this->dbname;
     } else {
         if (empty($this->dboptions['dbport'])) {
             $this->dboptions['dbport'] = 1521;
         }
         $dbstring = '//' . $this->dbhost . ':' . $this->dboptions['dbport'] . '/' . $this->dbname;
     }
     ob_start();
     if (empty($this->dboptions['dbpersist'])) {
         $this->oci = oci_new_connect($this->dbuser, $this->dbpass, $dbstring, 'AL32UTF8');
     } else {
         $this->oci = oci_pconnect($this->dbuser, $this->dbpass, $dbstring, 'AL32UTF8');
     }
     $dberr = ob_get_contents();
     ob_end_clean();
     if ($this->oci === false) {
         $this->oci = null;
         $e = oci_error();
         if (isset($e['message'])) {
             $dberr = $e['message'];
         }
         throw new dml_connection_exception($dberr);
     }
     // get unique session id, to be used later for temp tables stuff
     $sql = 'SELECT DBMS_SESSION.UNIQUE_SESSION_ID() FROM DUAL';
     $this->query_start($sql, null, SQL_QUERY_AUX);
     $stmt = $this->parse_query($sql);
     $result = oci_execute($stmt, $this->commit_status);
     $this->query_end($result, $stmt);
     $records = null;
     oci_fetch_all($stmt, $records, 0, -1, OCI_FETCHSTATEMENT_BY_ROW);
     oci_free_statement($stmt);
     $this->unique_session_id = reset($records[0]);
     //note: do not send "ALTER SESSION SET NLS_NUMERIC_CHARACTERS='.,'" !
     //      instead fix our PHP code to convert "," to "." properly!
     // Connection stabilised and configured, going to instantiate the temptables controller
     $this->temptables = new oci_native_moodle_temptables($this, $this->unique_session_id);
     return true;
 }
Exemplo n.º 5
0
 /**
  * Connect to the Oracle server using a unique connection
  *
  * @param string $username
  * @param string $password
  * @param string $connectionString
  * @param string $characterSet
  * @param int $sessionMode
  * @return resource
  * @throws \Jpina\Oci8\Oci8Exception
  * @see http://php.net/manual/en/function.oci-new-connect.php
  */
 protected function connect($username, $password, $connectionString = null, $characterSet = null, $sessionMode = null)
 {
     set_error_handler(static::getErrorHandler());
     $connection = oci_new_connect($username, $password, $connectionString, $characterSet, $sessionMode);
     restore_error_handler();
     return $connection;
 }
Exemplo n.º 6
0
 /**
 	Initialise an oracle database.
 
 	This database driver accepts the following parameters:
 	 * user:		The user used to connect to the database.
 	 * password:	The password of the user.
 	 * dbname:		The name of the database.
 	 * encoding:	The encoding used for the connection (defaults to UTF8).
 
 	@param	$aParams	The arguments of the connection.
 */
 public function __construct($aParams = array())
 {
     function_exists('oci_new_connect') or burn('ConfigurationException', sprintf(_WT('The "%s" PHP extension is required by this database driver.'), 'OCI8'));
     // oci_new_connect triggers a warning when the connection failed.
     $this->rLink = @oci_new_connect(array_value($aParams, 'user'), array_value($aParams, 'password'), array_value($aParams, 'dbname'), array_value($aParams, 'encoding', 'UTF8'));
     $this->rLink !== false or burn('DatabaseException', sprintf(_WT("Failed to connect to the database with the following error:\n%s"), array_value(oci_error(), 'message')));
 }
Exemplo n.º 7
0
 public function connect()
 {
     $this->conn = oci_new_connect($this->username, $this->password, $this->db_conn_string);
     if (!$this->conn) {
         $e = oci_error();
         trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
     }
 }
Exemplo n.º 8
0
 /**
  * Connect to MySQL, but not to a database
  *
  * @param string $dbuser Username
  * @param string $dbpassword Password
  * @return bool Success
  *
  */
 public function connect($dbuser = '', $dbpassword = '', $dbname = '')
 {
     if (!($this->dbh = oci_new_connect($dbuser, $dbpassword, $dbname))) {
         $err = ocierror();
         $this->register_error($err['message'], $err['code']);
         return false;
     } else {
         $this->clear_errors();
         return true;
     }
 }
Exemplo n.º 9
0
 /**
  * Constructor opens a connection to the database
  * @param string $module Module text for End-to-End Application Tracing
  * @param string $cid Client Identifier for End-to-End Application Tracing
  * @throws \Exception
  */
 public function __construct($module, $cid)
 {
     $this->conn = @oci_new_connect(O_USERNAME, O_PASSWORD, O_DATABASE, O_CHARSET);
     if (!$this->conn) {
         $m = oci_error();
         throw new \Exception("Cannot open connection to Oracle db " . $m["message"]);
     }
     // Record the "name" of the web user, the client info and the module.
     // These are used for end-to-end tracing in the DB.
     oci_set_client_info($this->conn, CLIENT_INFO);
     oci_set_module_name($this->conn, $module);
     oci_set_client_identifier($this->conn, $cid);
 }
Exemplo n.º 10
0
 /**
  * Connects to a database.
  *
  * @return void
  * @throws DibiException
  */
 public function connect(array &$config)
 {
     DibiConnection::alias($config, 'username', 'user');
     DibiConnection::alias($config, 'password', 'pass');
     DibiConnection::alias($config, 'database', 'db');
     DibiConnection::alias($config, 'charset');
     $this->connection = @oci_new_connect($config['username'], $config['password'], $config['database'], $config['charset']);
     // intentionally @
     if (!$this->connection) {
         $err = oci_error();
         throw new DibiDriverException($err['message'], $err['code']);
     }
 }
Exemplo n.º 11
0
 public static function getInstance()
 {
     if (!isset(self::$conn)) {
         // var_dump(SERVER); exit();
         self::$conn = oci_new_connect(USER, PASS, SERVER . "/" . SID, CHARTSET);
         if (!self::$conn) {
             $m = oci_error();
             echo $m['message'], "n";
             exit;
         }
     }
     return self::$conn;
 }
Exemplo n.º 12
0
 public function connect(array $params)
 {
     $database = "//" . $params["host"] . "/" . $params["database"];
     $encoding = isset($params["charset"]) ? $params["charset"] : null;
     $conn = oci_new_connect($params["user"], $params["password"], $database, $encoding);
     if ($conn) {
         $stmt = oci_parse($conn, "ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'");
         oci_execute($stmt, OCI_COMMIT_ON_SUCCESS);
         return $conn;
     } else {
         $e = oci_error();
         return $e["message"];
     }
 }
Exemplo n.º 13
0
 /** connect establishes the link
  * @return the class
  */
 public function connect()
 {
     try {
         if (!($this->link = @oci_new_connect(DATABASE_USERNAME, DATABASE_PASSWORD, '//' . DATABASE_HOST . '/' . DATABASE_NAME))) {
             throw new Exception(sprintf('Host: %s, Username: %s, Database: %s, Error: %s', DATABASE_HOST, DATABASE_USERNAME, DATABASE_NAME, @oci_error()));
         }
         if (!$this->link->select_db(DATABASE_NAME)) {
             throw new Exception(_('Issue working with the current DB, maybe it has not been created yet'));
         }
     } catch (Exception $e) {
         $this->debug(sprintf('Failed to %s: %s', __FUNCTION__, $e->getMessage()));
     }
     return $this;
 }
Exemplo n.º 14
0
 public function Connect($host, $user, $pass, $mode = OCI_DEFAULT, $type = ORA_CONNECTION_TYPE_DEFAULT)
 {
     switch ($type) {
         case ORA_CONNECTION_TYPE_PERSISTENT:
             $this->conn_handle = oci_pconnect($user, $pass, $host, $this->charset, $mode);
             break;
         case ORA_CONNECTION_TYPE_NEW:
             $this->conn_handle = oci_new_connect($user, $pass, $host, $this->charset, $mode);
             break;
         default:
             $this->conn_handle = oci_connect($user, $pass, $host, $this->charset, $mode);
     }
     return is_resource($this->conn_handle) ? true : false;
 }
Exemplo n.º 15
0
 /**
  * Connects to a database.
  * @return void
  * @throws DibiException
  */
 public function connect(array &$config)
 {
     $foo =& $config['charset'];
     $this->fmtDate = isset($config['formatDate']) ? $config['formatDate'] : 'U';
     $this->fmtDateTime = isset($config['formatDateTime']) ? $config['formatDateTime'] : 'U';
     if (isset($config['resource'])) {
         $this->connection = $config['resource'];
     } else {
         $this->connection = @oci_new_connect($config['username'], $config['password'], $config['database'], $config['charset']);
         // intentionally @
     }
     if (!$this->connection) {
         $err = oci_error();
         throw new DibiDriverException($err['message'], $err['code']);
     }
 }
Exemplo n.º 16
0
 /**
  * Establishes a connection to the database.
  * Includes php_interface/after_connect_d7.php on success.
  * Throws exception on failure.
  *
  * @return void
  * @throws \Bitrix\Main\DB\ConnectionException
  */
 protected function connectInternal()
 {
     if ($this->isConnected) {
         return;
     }
     if (($this->options & self::PERSISTENT) != 0) {
         $connection = oci_pconnect($this->login, $this->password, $this->database);
     } else {
         $connection = oci_new_connect($this->login, $this->password, $this->database);
     }
     if (!$connection) {
         throw new ConnectionException('Oracle connect error', $this->getErrorMessage());
     }
     $this->isConnected = true;
     $this->resource = $connection;
     $this->afterConnected();
 }
Exemplo n.º 17
0
 /**
  * Usually aborts on failure
  * If the failFunction is set to a non-zero integer, returns success
  */
 function open($server, $user, $password, $dbName)
 {
     if (!function_exists('oci_connect')) {
         throw new DBConnectionError($this, "Oracle functions missing, have you compiled PHP with the --with-oci8 option?\n");
     }
     $this->close();
     $this->mServer = $server;
     $this->mUser = $user;
     $this->mPassword = $password;
     $this->mDBname = $dbName;
     $this->mConn = oci_new_connect($user, $password, $dbName, "AL32UTF8");
     if ($this->mConn === false) {
         wfDebug("DB connection error\n");
         wfDebug("Server: {$server}, Database: {$dbName}, User: {$user}, Password: "******"...\n");
         wfDebug($this->lastError() . "\n");
     } else {
         $this->mOpened = true;
     }
     return $this->mConn;
 }
Exemplo n.º 18
0
 /**
  * Establishes a connection to the database.
  * Includes php_interface/after_connect_d7.php on success.
  * Throws exception on failure.
  *
  * @return void
  * @throws \Bitrix\Main\DB\ConnectionException
  */
 protected function connectInternal()
 {
     if ($this->isConnected) {
         return;
     }
     if (($this->options & self::PERSISTENT) != 0) {
         $connection = oci_pconnect($this->login, $this->password, $this->database);
     } else {
         $connection = oci_new_connect($this->login, $this->password, $this->database);
     }
     if (!$connection) {
         throw new ConnectionException('Oracle connect error', $this->getErrorMessage());
     }
     $this->isConnected = true;
     $this->resource = $connection;
     /** @noinspection PhpUnusedLocalVariableInspection */
     global $DB, $USER, $APPLICATION;
     if ($fn = \Bitrix\Main\Loader::getPersonal("php_interface/after_connect_d7.php")) {
         include $fn;
     }
 }
Exemplo n.º 19
0
 /**
  * Inits connection
  */
 protected function initConnection($username = null, $passwd = null)
 {
     if (is_null(self::$_parsedDsn['charset'])) {
         self::$_parsedDsn['charset'] = 'UTF8';
     }
     $session_mode = OCI_DEFAULT;
     if ($username === '/' && empty($passwd)) {
         $session_mode = OCI_CRED_EXT;
     }
     if ($this->getAttribute(PDO::ATTR_PERSISTENT)) {
         $this->_dbh = @oci_pconnect($username, $passwd, self::$_parsedDsn['dbname'], self::$_parsedDsn['charset'], $session_mode);
     } else {
         $this->_dbh = @oci_new_connect($username, $passwd, self::$_parsedDsn['dbname'], self::$_parsedDsn['charset'], $session_mode);
     }
     if (YII_DEBUG) {
         $this->checkError($this->_dbh);
     } else {
         if ($this->_dbh === false) {
             throw new CDbNoConnectionException('No DB');
         }
     }
 }
Exemplo n.º 20
0
 /**
  * {@inheritDoc}
  */
 public function connect()
 {
     if (is_resource($this->resource)) {
         return $this;
     }
     // localize
     $p = $this->connectionParameters;
     // given a list of key names, test for existence in $p
     $findParameterValue = function (array $names) use($p) {
         foreach ($names as $name) {
             if (isset($p[$name])) {
                 return $p[$name];
             }
         }
         return;
     };
     // http://www.php.net/manual/en/function.oci-connect.php
     $username = $findParameterValue(array('username'));
     $password = $findParameterValue(array('password'));
     $connectionString = $findParameterValue(array('connection_string', 'connectionstring', 'connection', 'hostname', 'instance'));
     $characterSet = $findParameterValue(array('character_set', 'charset', 'encoding'));
     $sessionMode = $findParameterValue(array('session_mode'));
     // connection modifiers
     $isUnique = $findParameterValue(array('unique'));
     $isPersistent = $findParameterValue(array('persistent'));
     if ($isUnique == true) {
         $this->resource = oci_new_connect($username, $password, $connectionString, $characterSet, $sessionMode);
     } elseif ($isPersistent == true) {
         $this->resource = oci_pconnect($username, $password, $connectionString, $characterSet, $sessionMode);
     } else {
         $this->resource = oci_connect($username, $password, $connectionString, $characterSet, $sessionMode);
     }
     if (!$this->resource) {
         $e = oci_error();
         throw new Exception\RuntimeException('Connection error', null, new Exception\ErrorException($e['message'], $e['code']));
     }
     return $this;
 }
Exemplo n.º 21
0
 /**
  * Multiple modes of connection are supported:
  *
  * a. Local Database
  *    $conn->Connect(false,'scott','tiger');
  *
  * b. From tnsnames.ora
  *    $conn->Connect($tnsname,'scott','tiger');
  *    $conn->Connect(false,'scott','tiger',$tnsname);
  *
  * c. Server + service name
  *    $conn->Connect($serveraddress,'scott,'tiger',$service_name);
  *
  * d. Server + SID
  *    $conn->connectSID = true;
  *    $conn->Connect($serveraddress,'scott,'tiger',$SID);
  *
  * @param string|false $argHostname DB server hostname or TNS name
  * @param string $argUsername
  * @param string $argPassword
  * @param string $argDatabasename Service name, SID (defaults to null)
  * @param int $mode Connection mode, defaults to 0
  *                  (0 = non-persistent, 1 = persistent, 2 = force new connection)
  *
  * @return bool
  */
 function _connect($argHostname, $argUsername, $argPassword, $argDatabasename = null, $mode = 0)
 {
     if (!function_exists('oci_pconnect')) {
         return null;
     }
     #adodb_backtrace();
     $this->_errorMsg = false;
     $this->_errorCode = false;
     if ($argHostname) {
         // added by Jorma Tuomainen <*****@*****.**>
         if (empty($argDatabasename)) {
             $argDatabasename = $argHostname;
         } else {
             if (strpos($argHostname, ":")) {
                 $argHostinfo = explode(":", $argHostname);
                 $argHostname = $argHostinfo[0];
                 $argHostport = $argHostinfo[1];
             } else {
                 $argHostport = empty($this->port) ? "1521" : $this->port;
             }
             if (strncasecmp($argDatabasename, 'SID=', 4) == 0) {
                 $argDatabasename = substr($argDatabasename, 4);
                 $this->connectSID = true;
             }
             if ($this->connectSID) {
                 $argDatabasename = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=" . $argHostname . ")(PORT={$argHostport}))(CONNECT_DATA=(SID={$argDatabasename})))";
             } else {
                 $argDatabasename = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=" . $argHostname . ")(PORT={$argHostport}))(CONNECT_DATA=(SERVICE_NAME={$argDatabasename})))";
             }
         }
     }
     //if ($argHostname) print "<p>Connect: 1st argument should be left blank for $this->databaseType</p>";
     if ($mode == 1) {
         $this->_connectionID = $this->charSet ? oci_pconnect($argUsername, $argPassword, $argDatabasename, $this->charSet) : oci_pconnect($argUsername, $argPassword, $argDatabasename);
         if ($this->_connectionID && $this->autoRollback) {
             oci_rollback($this->_connectionID);
         }
     } else {
         if ($mode == 2) {
             $this->_connectionID = $this->charSet ? oci_new_connect($argUsername, $argPassword, $argDatabasename, $this->charSet) : oci_new_connect($argUsername, $argPassword, $argDatabasename);
         } else {
             $this->_connectionID = $this->charSet ? oci_connect($argUsername, $argPassword, $argDatabasename, $this->charSet) : oci_connect($argUsername, $argPassword, $argDatabasename);
         }
     }
     if (!$this->_connectionID) {
         return false;
     }
     if ($this->_initdate) {
         $this->Execute("ALTER SESSION SET NLS_DATE_FORMAT='" . $this->NLS_DATE_FORMAT . "'");
     }
     // looks like:
     // Oracle8i Enterprise Edition Release 8.1.7.0.0 - Production With the Partitioning option JServer Release 8.1.7.0.0 - Production
     // $vers = oci_server_version($this->_connectionID);
     // if (strpos($vers,'8i') !== false) $this->ansiOuter = true;
     return true;
 }
Exemplo n.º 22
0
 /**
  * Usually aborts on failure
  * If the failFunction is set to a non-zero integer, returns success
  */
 function open($server, $user, $password, $dbName)
 {
     if (!function_exists('oci_connect')) {
         throw new DBConnectionError($this, "Oracle functions missing, have you compiled PHP with the --with-oci8 option?\n (Note: if you recently installed PHP, you may need to restart your webserver and database)\n");
     }
     $this->close();
     $this->mServer = $server;
     $this->mUser = $user;
     $this->mPassword = $password;
     $this->mDBname = $dbName;
     if (!strlen($user)) {
         # e.g. the class is being loaded
         return;
     }
     $session_mode = $this->mFlags & DBO_SYSDBA ? OCI_SYSDBA : OCI_DEFAULT;
     if ($this->mFlags & DBO_DEFAULT) {
         $this->mConn = oci_new_connect($user, $password, $dbName, $this->defaultCharset, $session_mode);
     } else {
         $this->mConn = oci_connect($user, $password, $dbName, $this->defaultCharset, $session_mode);
     }
     if ($this->mConn == false) {
         wfDebug("DB connection error\n");
         wfDebug("Server: {$server}, Database: {$dbName}, User: {$user}, Password: "******"...\n");
         wfDebug($this->lastError() . "\n");
         return false;
     }
     $this->mOpened = true;
     # removed putenv calls because they interfere with the system globaly
     $this->doQuery('ALTER SESSION SET NLS_TIMESTAMP_FORMAT=\'DD-MM-YYYY HH24:MI:SS.FF6\'');
     $this->doQuery('ALTER SESSION SET NLS_TIMESTAMP_TZ_FORMAT=\'DD-MM-YYYY HH24:MI:SS.FF6\'');
     return $this->mConn;
 }
Exemplo n.º 23
0
    public function check_switchover_status($db_user, $db_password, $db_hostname, $db_service, $expected_status, $interval, $limit) {
        global $error;

        for ($count = 0; $count < $limit; $count++) {
            $conn_db = oci_new_connect($db_user, $db_password, '//' . $db_hostname . '/' . $db_service, '', OCI_SYSDBA);
            $sql = 'select switchover_status from v$database';
            $state_id = oci_parse($conn_db, $sql);
            $result = oci_execute($state_id);
            if ($result != TRUE) {
                oci_close($conn_db);
                sleep($interval);
                continue;
            }
            $row = oci_fetch_array($state_id, OCI_BOTH);
            if ($row[0] == $expected_status) {
                oci_close($conn_db);
                return(TRUE);
            } else {
                oci_close($conn_db);
                sleep($interval);
            }
        }
        oci_close($conn_db);
        $error->set_msg("Switchover status is not appropriate. Now in " . $row[0] . ". Should be " . $expected_status . ".");
        return(ERROR);
    }
Exemplo n.º 24
-1
 /**
  * Connects to a database.
  * @return void
  * @throws Dibi\Exception
  */
 public function connect(array &$config)
 {
     $foo =& $config['charset'];
     $this->fmtDate = isset($config['formatDate']) ? $config['formatDate'] : 'U';
     $this->fmtDateTime = isset($config['formatDateTime']) ? $config['formatDateTime'] : 'U';
     if (isset($config['resource'])) {
         $this->connection = $config['resource'];
     } elseif (empty($config['persistent'])) {
         $this->connection = @oci_new_connect($config['username'], $config['password'], $config['database'], $config['charset']);
         // intentionally @
     } else {
         $this->connection = @oci_pconnect($config['username'], $config['password'], $config['database'], $config['charset']);
         // intentionally @
     }
     if (!$this->connection) {
         $err = oci_error();
         throw new Dibi\DriverException($err['message'], $err['code']);
     }
     if (isset($config['schema'])) {
         $this->query('ALTER SESSION SET CURRENT_SCHEMA=' . $config['schema']);
     }
 }
Exemplo n.º 25
-1
 protected function &connect($new = false, $suppress = false)
 {
     $this->setConnectionString();
     isset($this->connectionSettings['session_mode']) ?: ($this->connectionSettings['session_mode'] = null);
     if ($new) {
         $resource = oci_new_connect($this->connectionSettings['username'], $this->connectionSettings['password'], $this->connectionString, $this->connectionSettings['charset'], $this->connectionSettings['session_mode']);
         if (!$resource) {
             $t = count($this->errorStack);
             $this->errorStack[$t]['error'] = oci_error($this->resource);
             $this->errorStack[$t]['trace'] = debug_backtrace(0, 3);
             Error::getMessage(null, $this->errorStack[$t]['trace'], $this->errorStack[$t]['error'], $suppress);
         }
         return $resource;
     } else {
         $this->resource = oci_connect($this->connectionSettings['username'], $this->connectionSettings['password'], $this->connectionString, $this->connectionSettings['charset'], $this->connectionSettings['session_mode']);
         if (!$this->resource) {
             $t = count($this->errorStack);
             $this->errorStack[$t]['error'] = oci_error($this->resource);
             $this->errorStack[$t]['trace'] = debug_backtrace(0, 3);
             Error::getMessage(null, $this->errorStack[$t]['trace'], $this->errorStack[$t]['error'], $suppress);
         }
         return $this->resource;
     }
 }
Exemplo n.º 26
-1
 /**
  * Doctrine Oracle adapter constructor
  *
  * <code>
  * $conn = new Doctrine_Adapter_Oracle(array('dbname'=>'db','username'=>'usr','password'=>'pass'));
  * </code>
  *
  * or
  *
  * <code>
  * Doctrine_Manager::connection(array('oracle:dbname=SID;charset=NLS_CHARACTERSET;persistent=true','usr', 'pass'),"doctrine_connection_name")
  * </code>
  *
  * @param string $name
  * @return void
  */
 public function __construct($config = array(), $username = null, $password = null)
 {
     if (is_string($config)) {
         $config = str_replace("oracle:", "", $config);
         $parts = explode(";", $config);
         foreach ($parts as $part) {
             $e = explode("=", $part);
             $key = array_shift($e);
             $this->config[$key] = implode('=', $e);
         }
         if ($username) {
             $this->config['username'] = $username;
         }
         if ($password) {
             $this->config['password'] = $password;
         }
     } else {
         if (!isset($config['password']) || !isset($config['username'])) {
             throw new Doctrine_Adapter_Exception('config array must have at least a username and a password');
         }
         $this->config['username'] = $config['username'];
         $this->config['password'] = $config['password'];
         $this->config['dbname'] = $config['dbname'];
         if (isset($config['charset'])) {
             $this->config['charset'] = $config['charset'];
         }
         if (isset($config['persistent'])) {
             $this->config['persistent'] = $config['persistent'];
         }
     }
     if ($this->config['persistent'] == 'true') {
         $this->connection = @oci_pconnect($this->config['username'], $this->config['password'], $this->config['dbname'], $this->config['charset']);
     } else {
         $this->connection = @oci_new_connect($this->config['username'], $this->config['password'], $this->config['dbname'], $this->config['charset']);
     }
     if ($this->connection === false) {
         throw new Doctrine_Adapter_Exception(sprintf("Unable to Connect to :'%s' as '%s'", $this->config['dbname'], $this->config['username']));
     }
 }