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.

77 lines
1.7 KiB

  1. <?php
  2. /**
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage db
  7. * @since 2011-11-10
  8. */
  9. /**
  10. * @property Mongo $connection
  11. */
  12. class MongoDriver extends NoSqlDbDriver
  13. {
  14. public function find($data, $params = array(), $cache_key = null)
  15. {
  16. }
  17. public function insert($table, $bind, $on_duplicate = array())
  18. {
  19. return parent::insert($table, $bind, $on_duplicate);
  20. }
  21. public function update($table, $bind, $where = '')
  22. {
  23. return parent::update($table, $bind, $where);
  24. }
  25. public function delete($table, $where = '')
  26. {
  27. return parent::delete($table, $where);
  28. }
  29. public function getInsertId($table = null, $key = null)
  30. {
  31. // TODO: Implement getInsertId() method.
  32. }
  33. public function isConnected()
  34. {
  35. if (!is_null($this->connection)) {
  36. return $this->connection->connected;
  37. } else {
  38. return false;
  39. }
  40. }
  41. public function disconnect()
  42. {
  43. if ($this->isConnected()) {
  44. $this->connection->close();
  45. }
  46. $this->connection = null;
  47. }
  48. protected function connect()
  49. {
  50. if ($this->connection) {
  51. return;
  52. }
  53. $host = $this->config['hostname'];
  54. $port = isset($this->config['port']) ? ':' . (string) $this->config['port'] : '';
  55. $this->config = array(
  56. 'username' => $this->config['username'],
  57. 'password' => $this->config['password'],
  58. 'db' => $this->config['database']
  59. );
  60. $this->connection = new Mongo('mongodb://' . $host . $port, $this->config);
  61. }
  62. }