You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.4 KiB

<?php
/**
* @copyright NetMonsters <team@netmonsters.ru>
* @link http://netmonsters.ru
* @package Majestic
* @subpackage db
* @since 2010-02-16
* @version SVN: $Id$
* @filesource $URL$
*/
abstract class DbDriver
{
/**
* Database connection
*
* @var object
*/
protected $connection = null;
/**
* Configuration data
*
* @var array
*/
protected $config = array();
public function __construct($config)
{
$this->checkConfig($config);
$this->config = $config;
}
protected function checkConfig($config)
{
$required = array('database', 'username', 'password', 'hostname');
foreach ($required as $option) {
if (!isset($config[$option])) {
throw new Exception('Configuration must have a "' . $option . '".');
}
}
}
public function getConnection()
{
$this->connect();
return $this->connection;
}
/* Abstract methods */
abstract public function insert($table, $data);
abstract public function update($table, $data, $condition);
abstract public function delete($table, $condition);
abstract public function getInsertId($table = null, $key = null);
abstract public function isConnected();
abstract public function disconnect();
abstract protected function connect();
}