This is the code I created.
It is working fine but I get the following error message:
Runtime notice: Declaration of Database_custom::getInstance() should be compatible with that of Database::getInstance() in /var/www/html/infobase/system/drivers/DB_Oracle_custom.php on line 42
I get this error by calling:
$db2 = Database_custom::getInstance($GLOBALS['TL_CONFIG']['dbUser_Infobase'],$GLOBALS['TL_CONFIG']['dbPass_Infobase'], $GLOBALS['TL_CONFIG']['dbSid_Infobase']);
Code:
<?php if (!defined('TL_ROOT')) die('You can not access this file directly!');
class Database_custom extends Database
{
protected static $myInstance;
protected $user;
protected $pass;
protected $sid;
public static function getInstance($user,$pass,$sid) {
if (!is_object(self::$myInstance)) {
self::$myInstance = new DB_Oracle_custom($user,$pass,$sid);
}
return self::$myInstance;
}
public function prepare($strQuery)
{
$strClass = 'DB_Oracle_Statement_custom';
$objStatement = new $strClass($this->resConnection, $this->blnDisableAutocommit);
return $objStatement->prepare($strQuery); // prepare oproepen van klasse DB_Oracle_Statement
}
/**
* Abstract database driver methods
*/
protected function connect(){}
protected function disconnect(){}
protected function get_error(){}
protected function begin_transaction(){}
protected function commit_transaction(){}
protected function rollback_transaction(){}
protected function list_fields($strTable){}
protected function set_database($strDatabase){}
}
/**
* Class DB_Oracle_custom
*
* Driver class for Oracle databases to connect to external database.
* @copyright Flexima 2010
* @author Frederick Eyland <http://www.flexima.be>
* @package Driver
*/
class DB_Oracle_custom extends Database_custom
{
protected $user;
protected $pass;
protected $sid;
public function __construct($user,$pass,$sid)
{
$this->connect2($user,$pass,$sid);
if (!is_resource($this->resConnection) && !is_object($this->resConnection))
{
throw new Exception(sprintf('Could not connect to database (%s)', $this->error));
}
}
protected function connect2($user,$pass,$sid)
{
$this->resConnection = @oci_connect($user,$pass,$sid);
}
}
class DB_Oracle_Statement_custom extends DB_Oracle_Statement
{
/**
* Escape parameters and execute the current statement
* @return object
* @throws Exception
*/
public function execute()
{
$arrParams = func_get_args();
if (is_array($arrParams[0]))
{
$arrParams = array_values($arrParams[0]);
}
$arrParams = $this->escapeParams($arrParams);
$this->strQuery = preg_replace('/%([^bcdufosxX])/', '%%$1', $this->strQuery);
$this->strQuery = preg_replace('/%%+/', '%%', $this->strQuery);
if (($this->strQuery = @vsprintf($this->strQuery, $arrParams)) == false)
{
throw new Exception('Too few arguments to build the query string');
}
// Execute the query
if (($this->resResult = $this->execute_query()) == false)
{
throw new Exception(sprintf('Query error: %s (%s)', $this->error, $this->strQuery));
}
// Check whether there is a result
if (!is_resource($this->resResult) && !is_object($this->resResult))
{
$this->debugQuery();
return $this;
}
$strClass = 'DB_Oracle_Result';
$objResult = new $strClass($this->resResult, $this->strQuery);
$this->debugQuery($objResult);
return $objResult;
}
}
?>
Bookmarks