<?php
/**
*
* @author Benjamin Gillissen <hide@address.com>
*
* **************************************************************
Copyright (C) 2009 Benjamin Gillissen
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details at:
http://www.gnu.org/copyleft/gpl.html
* **************************************************************
*/
class db_oracle extends db_accessor {
private $phpext = 'oci8';
private $isconn = FALSE;
private $_HDL;
public function __construct($DBRef){
parent::__construct($DBRef);
}
protected function connect(){
if ( !$this->checkphpext($this->phpext) ){
return errors::getnew('No oracle extention could be found or loaded on this system,
plz contact the administrator and ask for oracle (oci8) support in php or simply use an other vendor.', CORE_LOG_ERR, 'DB');
}
if ( !$conf = $this->getconf() ){
return errors::getnew('No configuration could be loaded for DBRef "'.$this->DBRef.'",
plz check your db.conf.php file or load a valid db configuration with that reference.', CORE_LOG_ERR, 'DB');
} elseif ( !isset($conf['user']) ){
return errors::getnew('Configuration for DBRef "'.$this->DBRef.'" is incomplete,
plz set the "user" key in your conf for this DBRef.', CORE_LOG_ERR, 'DB');
} elseif ( !isset($conf['pass']) ){
return errors::getnew('Configuration for DBRef "'.$this->DBRef.'" is incomplete,
plz set the "pass" key in your conf for this DBRef.', CORE_LOG_ERR, 'DB');
}
if ( isset($conf['db']) ){
$this->_HDL = ociPLogon($conf['user'], $conf['mdp'], $conf['db']);
} else {
$this->_HDL = ociPLogon($conf['user'], $conf['mdp']);
}
if ( !$this->_HDL ){
$e = oci_error();
return errors::getnew('Connection could not be established with mysql database server with DBRef "'.$this->DBRef.'" :
['.$e['code'].'] '.$e['message'], CORE_LOG_ERR, 'DB');
}
$this->isconn = TRUE;
return TRUE;
}
protected function disconnect(){
if ( $this->isconnected() ){
$this->isconn = FALSE;
return @oci_close($this->_HDL);
}
return TRUE;
}
protected function isconnected(){
return $this->isconn;
}
protected function sendquery($q){
if ( empty($q) ){
return errors::getnew('SQL query is empty', CORE_LOG_WARNING, 'DB');
}
if ( !$this->isconnected() ){
$try = $this->connect();
if ( CORE::isError($try) ){
return errors::getnew('You are about to execute an SQL query on a handler that as not yet been connected,
the trouble is that it was not able to connect to the server :
'.$try->getmsg(), CORE_LOG_WARNING, 'DB');
}
}
$statement = oci_parse($this->_HDL, $q);
$result = oci_execute($statement);
if ( !$result ){
$e = oci_error();
return errors::getnew('SQL query "'.$q.'" has returned an error : ['.$e['code'].'] '.$e['message'], CORE_LOG_ERR, 'DB');
}
return $result;
}
protected function insert($q){
}
protected function update($q){
}
protected function delete($q){
}
protected function getone($q){
}
protected function getall($q){
}
protected function fetch($q){
static $bool=TRUE;
static $result;
if ( $bool ){
$result = $this->sendquery($q);
unset($q);
if ( CORE::isError($result) ){
return $result;
}
}
$bool = FALSE;
$row = @oci_fetch_array($result, OCI_ASSOC);
if ( $row === FALSE ){
$bool = TRUE;
unset($result);
return FALSE;
}
return $row;
}
}