Location: PHPKode > scripts > Persist Class > persist-class/persistclass/dbconnection/DbConnectionOracle.php
<?php

class DbConnectionOracle extends DbConnection {
	
	private $transaction = false;
	
	public function connect($username, $password, $db) {
		if($this->link)	$this->closeConnection();
		$this->link = @oci_pconnect($username, $password, $db);
		if(!$this->link) {
			$e = @oci_error();
			throw new ConnectionException('Could not connect: ' . $e['message']);
		}
	}
	
	public function cloneConnection() {
		$cloned = new DbConnectionOracle();
		$cloned->link = $this->link;
		$cloned->transaction = $this->transaction;
		return $cloned;
	}


	public function query($q) {
		if(!$this->link)
			throw new ConnectionException('No connected to database');
		if($q == null)
			throw new QueryException('Query string is null');
		$stid = oci_parse($this->link, $q);
		if(!$stid) {
			$e = oci_error($this->link);
			throw new QueryException('Query failed: '.$q.' Error: '.$e['message']. ' Sql: '. $q);
		}
		$suc;
		if($this->transaction)
			$suc = @oci_execute($stid, OCI_DEFAULT);
		else
			$suc = @oci_execute($stid);
		if(!$suc) {
			$e = oci_error($this->link);
			throw new QueryException('Query failed: '.$q.' Error: '.$e['message']. ' Sql: '. $q);
		}
		$this->result = $stid;
		$this->numRows = oci_num_rows($this->result);
		return $this->numRows;
	}

	public function next() {
		return @oci_fetch_assoc($this->result);
	}

	public function getLastId() {
		throw new DbException('getLastId can\'t be implemented for Oracle');
	}

	public function closeConnection() {
		@oci_close($this->link);
		$this->link = null;
	}

	public function escape($string, $quoted = true) {
		$string = addslashes($string);
		$string = $quoted ? '\'' . $string . '\'' : $string;
		return $string;
	}
	
	public function startTransaction() {
		$this->transaction = true;
	}
	
	public function commit() {
		$this->transaction = false;
		$r = @oci_commit($this->link);
		if(!$r) {
			$e = oci_error($this->link);
			throw new QueryException('Error at commit at commit: '.$q.' Error: '.$e['message']. ' Sql: '. $q);
		}
	}
	
	public function rollBack() {
		@oci_rollback($this->link);
	}

}


?>
Return current item: Persist Class