connectionUri = $connectionString; $codePage = $this->connectionUri->getQueryPart("codepage"); $codePage = ($codePage == "") ? 'UTF8' : $codePage; $tns = DbOci8Driver::getTnsString($this->connectionUri); $this->conn = oci_connect( $this->connectionUri->getUsername(), $this->connectionUri->getPassword(), $tns, $codePage ); if (!$this->conn) { $error = oci_error(); throw new DatabaseException($error['message']); } } /** * @param Uri $connUri * @return string */ public static function getTnsString(Uri $connUri) { $protocol = $connUri->getQueryPart("protocol"); $protocol = ($protocol == "") ? 'TCP' : $protocol; $port = $connUri->getPort(); $port = ($port == "") ? 1521 : $port; $svcName = preg_replace('~^/~', '', $connUri->getPath()); $host = $connUri->getHost(); return "(DESCRIPTION = " . " (ADDRESS = (PROTOCOL = $protocol)(HOST = $host)(PORT = $port)) " . " (CONNECT_DATA = (SERVICE_NAME = $svcName)) " . ")"; } public function __destruct() { $this->conn = null; } /** * @param $sql * @param null $array * @return resource * @throws DatabaseException */ protected function getOci8Cursor($sql, $array = null) { list($query, $array) = SqlBind::parseSQL($this->connectionUri, $sql, $array); // Prepare the statement $stid = oci_parse($this->conn, $query); if (!$stid) { $error = oci_error($this->conn); throw new DatabaseException($error['message']); } // Bind the parameters if (is_array($array)) { foreach ($array as $key => $value) { oci_bind_by_name($stid, ":$key", $value); } } // Perform the logic of the query $result = oci_execute($stid, $this->transaction); // Check if is OK; if (!$result) { $error = oci_error($stid); throw new DatabaseException($error['message']); } return $stid; } /** * @param $sql * @param null $params * @return Oci8Iterator * @throws DatabaseException */ public function getIterator($sql, $params = null) { $cur = $this->getOci8Cursor($sql, $params); return new Oci8Iterator($cur); } /** * @param $sql * @param null $array * @return null * @throws DatabaseException */ public function getScalar($sql, $array = null) { $cur = $this->getOci8Cursor($sql, $array); $row = oci_fetch_array($cur, OCI_RETURN_NULLS); if ($row) { $scalar = $row[0]; } else { $scalar = null; } oci_free_cursor($cur); return $scalar; } /** * @param $tablename * @return array * @throws DatabaseException */ public function getAllFields($tablename) { $cur = $this->getOci8Cursor(SqlHelper::createSafeSQL("select * from :table", array(':table' => $tablename))); $ncols = oci_num_fields($cur); $fields = array(); for ($i = 1; $i <= $ncols; $i++) { $fields[] = strtolower(oci_field_name($cur, $i)); } oci_free_statement($cur); return $fields; } public function beginTransaction() { $this->transaction = OCI_NO_AUTO_COMMIT; } /** * @throws DatabaseException */ public function commitTransaction() { if ($this->transaction == OCI_COMMIT_ON_SUCCESS) { throw new DatabaseException('No transaction for commit'); } $this->transaction = OCI_COMMIT_ON_SUCCESS; $result = oci_commit($this->conn); if (!$result) { $error = oci_error($this->conn); throw new DatabaseException($error['message']); } } /** * @throws DatabaseException */ public function rollbackTransaction() { if ($this->transaction == OCI_COMMIT_ON_SUCCESS) { throw new DatabaseException('No transaction for rollback'); } $this->transaction = OCI_COMMIT_ON_SUCCESS; oci_rollback($this->conn); } /** * @param $sql * @param null $array * @return bool * @throws DatabaseException */ public function execute($sql, $array = null) { $cur = $this->getOci8Cursor($sql, $array); oci_free_cursor($cur); return true; } /** * @return resource */ public function getDbConnection() { return $this->conn; } /** * @param $name * @throws NotImplementedException */ public function getAttribute($name) { throw new NotImplementedException('Method not implemented for OCI Driver'); } /** * @param $name * @param $value * @throws NotImplementedException */ public function setAttribute($name, $value) { throw new NotImplementedException('Method not implemented for OCI Driver'); } /** * @param $sql * @param null $array * @throws NotImplementedException */ public function executeAndGetId($sql, $array = null) { throw new NotImplementedException('Method not implemented for OCI Driver'); } /** * @return \ByJG\AnyDataset\Db\DbFunctionsInterface|void * @throws NotImplementedException */ public function getDbHelper() { throw new NotImplementedException('Method not implemented for OCI Driver'); } /** * @return Uri */ public function getUri() { return $this->connectionUri; } /** * @throws NotImplementedException */ public function isSupportMultRowset() { throw new NotImplementedException('Method not implemented for OCI Driver'); } /** * @param $multipleRowSet * @throws NotImplementedException */ public function setSupportMultRowset($multipleRowSet) { throw new NotImplementedException('Method not implemented for OCI Driver'); } } __halt_compiler();----SIGNATURE:----WgkYS3CUc6zKIHZKtSfSiz1nLsBwPL5ae4/mhMQd99hPfuGT0bnUD3v12byktyaftQLIL9D9Z0Zo66Q9fE0wuB6MTE2roh/7b5FJt1UxzK4RhA6+mH7CLU+67VUuJsaM4y2b6jJTEiVB88yTmlQ0MQBAuejP/3W1cZTgNm0DU0VuV06mmmda3NOnTflad2vPYZyzM6HT6S7b9mi2r8j59jTuVp1m/lkWT/WZCCivq9n2anrsyvoLQGkLsUjygGn09FBC9aGWhFMc+Ms3F/it+7vgPY8PMuGzDV7lRmJqFw79lg2GO5i/pSgMTs+q6rP7m5dzo3nkLALfWcq64+gRWiLvuDg7R4fS3M1eAL6L7yzkJeVWIWv6y2tRKSvx85we5C1AfCpI1Bqiu6SEMLijeoxB0jLbpahCDfdF4HNSsQjpKwHpKedMdaTPfh9M2a2RkWLLaHj/XCRDsS9VuisWbT/z9W/wnLrFpZKHZrVWxP/zHktZKk1iLiJ1CUNwearI6GdjkcMGGc7u4ViBiTGiGS0OrFz1NC3gKSrFiIVDBah3OafyihRKa+5jIHleGTqWh6CWaZLFGmBDRqlsDnghW2mR5IaMh/KYZmbv7bRBU+0AKoQjdYKVrIsmscq+WJFs0abQB2IoMJOwFAnEEmN7+n+uhNmS8GmYGz9NdedDKh0=----ATTACHMENT:----ODY2OTU2NjcyMTUyMzg1MCAyMTYwMjc2NTM0NDYxMDY5IDMxNTA1OTM5NTc5OTUxOTE=