<?php
	/**
	* Open a connection with the database server using oracle extension.
	*
	* @copyright Trusto Tech 2015-2016
	* @author  Taha Sayyad <info@trustotech.com>
	* @package System\Database\Adapters
	*/
	class OracleAdapter extends DBConnectionParameters implements DBAdapterInterface {

		private $_DBConnection;
		
		public function __construct() {
            parent::_setParameters();
            self::connect();
		}
		
		public function query($query) {
			if (empty($query))
				return false;
			return oci_execute(oci_parse($query));
		}
		
		public function rowsno($result) {
			return oci_num_rows($result);
		}
		
		public function setNames() {
			self::query("SET NAMES 'utf8'"); 
			self::query('SET CHARACTER SET utf8'); 
		}
		
		public function fetch($result) {
			return oci_fetch_array($result, OCI_ASSOC+OCI_RETURN_NULLS);
		}
		
		public function id() {}

		public function assoc($result) {
			return oci_fetch_assoc($result);
		}

		public function getConnectionObject() {
			return $this->_DBConnection;
		}

		private function connect() {
			$this->_DBConnection = oci_connect(parent::_getDBUsername(), parent::_getDBPassword(), parent::_getDBHostname());
			if ($this->_DBConnection) {
				if (mssql_select_db(parent::_getDBName(), $this->_DBConnection))
					return false;
			} else
				return false;
		}

	}