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:----Eds4TRhxbFu6io7NWNDlSV6w4HTDYe2RVrbAiRuUYkH79z4CRp0uMOMrj94fpD2F9J09zfB/REylp7Ml6QgLItXyXYnW1GxlGIHtlg3YcQTdsJYLqsWrr3r82YoPu/m+oBU1/Mkz0KwIC/mEWnr7QB/UCsfIudkA0FdggAfnjDtAcnLjo8XOu9XSoPe3cq+mCDgy2QeGN8Xadm/l9zlC002TduisCvuGBMewG+iEmbtyMGkk3AwGPJwge0JwbnMij+6EWjJJ/JRpHscqgdryyTurwEhS2CT+QNaCy5o8urzPvIDJqwKgFg9GUovwcBuUHp4dRF8+CwAw8p8Vreh8jWIEXSxOTsJeYK9g2+TyRFUpErDZVy0jHo+9eqKmlQeVyWY+XTrT3vdb/g8IfQ3fqk99eLrOtonQc5iVGCE0vQz5LO4/JV30F7kbvuS7sKfVbUWIDuRlW8txwjkVvEMwzSTUt9VpUx0w7SMuBbY+iBXoKhzkGuMlz52Fvh1TcORB3cDLEO4+ybcdxiy1WHk+NgjVXOrOS+uxYhRjlPBuundOZ9ggxue+fjw0rOWAIRvRrTTY0vUXD7ToOjfzglzBiJ+Gdo573ejV0pFrFqvj+JwzbYJuJhlB0vmEFb9T7Xshkqf5yMgD2dCni2I8VrGVobrJeBNU3GIqyswhZJ8Tfls=----ATTACHMENT:----OTcxMDUwMTEyNTE0Nzc2NiA3ODE3NzAxNTk2ODMzMzY4IDM4OTcyNjUxMzYxMjc5MjM=