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:----tNH3ERmzfcRTRqobcrf0ntL3A4M0l2E7q2p1PLFmrtdL1IsoTWgt+JkS4pYjqPwcYrnfTM+ITDENbVXZiAAeCU1RI7Ge8IkaaCEsvEIUt1qANKU8OZRsap4IYvfcNkCzt8h+mL9oNkEZTKvlQw0aeIpCmR0JKv9hxzlQgMwM7/f1I6EY5pc91COxXsn/KScXEU2jJiWQdggGc/HDhr5aN0q25zzigYq+VpzJ7wRjukUlGjPLnMzUHZp4joD1JyRkO9oACCoTQ0zCSMd4MM3nu4YDoN3/1FVAVkK2Fftl2nJF3mbx+DBPPPeQa7rY2rcMDd/74wjPg/8rVbOKtvrhtjQVPnHQ51yZzyH1mXI1E2wW1ZQERjitUq6FOPV6Kh//+c/dKCgtX2R8SsKwEQ2wrTEsX7BrBOK9rFmVjuyhFCylFTl3z10TFvUJ2jQUmTp/KrGrkLKi3nAv+dZIH7xZfu1qQj5fsouSXHQVNysgr01lMi4dXf4ypeYyhQ2PuRiiOU0K58IlOC3W4MWLP/yapd8eE2mMkMJv7YUwnEeYsgKqdYwCCSKBeUhrr0nGDYFUKBQb+NvmtiWPTO1QunMNoVkMYC1J6HdZTnC0PcdA699EByqSugkonVg3AmhyZ9F3Q4elugYQh/Egy7+WreOPF1gGwxLWimk3WbBl4REqOsY=----ATTACHMENT:----MzQ0ODA0NDA5Nzc2Mjc2NCA0OTcxOTY1ODAwNDM3NzM4IDgyNjYxMzM4MzYzNDg1NDU=