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.

66 lines
1.4 KiB

  1. <?php
  2. /**
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage db
  7. * @since 2010-02-16
  8. * @version SVN: $Id$
  9. * @filesource $URL$
  10. */
  11. abstract class DbDriver
  12. {
  13. /**
  14. * Database connection
  15. *
  16. * @var object
  17. */
  18. protected $connection = null;
  19. /**
  20. * Configuration data
  21. *
  22. * @var array
  23. */
  24. protected $config = array();
  25. public function __construct($config)
  26. {
  27. $this->checkConfig($config);
  28. $this->config = $config;
  29. }
  30. protected function checkConfig($config)
  31. {
  32. $required = array('database', 'username', 'password', 'hostname');
  33. foreach ($required as $option) {
  34. if (!isset($config[$option])) {
  35. throw new Exception('Configuration must have a "' . $option . '".');
  36. }
  37. }
  38. }
  39. public function getConnection()
  40. {
  41. $this->connect();
  42. return $this->connection;
  43. }
  44. /* Abstract methods */
  45. abstract public function insert($table, $data);
  46. abstract public function update($table, $data, $condition);
  47. abstract public function delete($table, $condition);
  48. abstract public function getInsertId($table = null, $key = null);
  49. abstract public function isConnected();
  50. abstract public function disconnect();
  51. abstract protected function connect();
  52. }