Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed compatibility for Mongo v1.3 driver

  • Loading branch information...
commit cfc3699e5f74d70d53a4262a7bda8aab6e8fa6d2 1 parent 02224d9
Alex Bilbie authored
Showing with 20 additions and 8 deletions.
  1. +20 −8 src/MongoQB/Builder.php
28 src/MongoQB/Builder.php
View
@@ -1352,15 +1352,15 @@ public function addIndex($collection = '', $fields = array(),
}
}
- if ($this->_dbhandle->{$collection}->ensureIndex($keys, $options)
- === true) {
+ try {
+ $this->_dbhandle->{$collection}->ensureIndex($keys, $options);
$this->_clear($collection, 'add_index');
-
return $this;
- } else {
- // @codeCoverageIgnoreStart
+ }
+ // @codeCoverageIgnoreStart
+ catch (\Exception $e) {
throw new \MongoQB\Exception('An error occurred when trying to add an
- index to MongoDB Collection');
+ index to MongoDB Collection: ' . $e->getMessage());
// @codeCoverageIgnoreEnd
}
}
@@ -1503,8 +1503,20 @@ private function _connect()
} // @codeCoverageIgnoreEnd
try {
- $this->_connection = new \Mongo($this->_dsn, $options);
- $this->_dbhandle = $this->_connection->{$this->_dbname};
+ // @codeCoverageIgnoreStart
+ if (phpversion('Mongo') >= 1.3)
+ {
+ unset($options['persist']);
+ $this->_connection = new \MongoClient($this->_dsn, $options);
+ $this->_dbhandle = $this->_connection->{$this->_dbname};
+ }
+
+ else
+ {
+ $this->_connection = new \Mongo($this->_dsn, $options);
+ $this->_dbhandle = $this->_connection->{$this->_dbname};
+ }
+ // @codeCoverageIgnoreEnd
return $this;
}
// @codeCoverageIgnoreStart
Please sign in to comment.
Something went wrong with that request. Please try again.