40 lines
756 B
PHP
40 lines
756 B
PHP
|
<?php
|
||
|
|
||
|
class Db extends Singleton {
|
||
|
|
||
|
private $_driver;
|
||
|
|
||
|
public function init() {
|
||
|
$params = Config::get('app:DB');
|
||
|
$driver = $params['engine'];
|
||
|
unset($params['engine']);
|
||
|
switch ($driver) {
|
||
|
case 'pgsql' : default :
|
||
|
$this->_driver = new Pgsql(); break;
|
||
|
}
|
||
|
call_user_func_array(array($this->_driver, 'connect'), $params);
|
||
|
}
|
||
|
|
||
|
public function q($q, $params = array()) {
|
||
|
if (! $this->_driver) {
|
||
|
$this->init();
|
||
|
}
|
||
|
return $this->_driver->q($q);
|
||
|
}
|
||
|
|
||
|
public function getRows($result, $key = false) {
|
||
|
if (! $this->_driver) {
|
||
|
$this->init();
|
||
|
}
|
||
|
return $this->_driver->getRows($result, $key);
|
||
|
}
|
||
|
|
||
|
public function getRow($result) {
|
||
|
if (! $this->_driver) {
|
||
|
$this->init();
|
||
|
}
|
||
|
return $this->_driver->getRow($result);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
?>
|