Skip to content

Commit

Permalink
Change ActiveMongo::connect() to enable MongoDB Auth
Browse files Browse the repository at this point in the history
ActiveMongo::connect($db, $host='localhost', $user = null, $pwd=null)
  • Loading branch information
DrZippie authored and crodas committed Apr 8, 2010
1 parent 0d36f80 commit 095418d
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lib/ActiveMongo.php
Expand Up @@ -116,6 +116,20 @@ abstract class ActiveMongo implements Iterator, Countable, ArrayAccess
* @type string
*/
private static $_host;
/**
* User (Auth)
*
* @type string
*/
private static $_user;

/**
* Password (Auth)
*
* @type string
*/
private static $_pwd;

/**
* Current document
*
Expand Down Expand Up @@ -238,13 +252,17 @@ final public static function install()
*
* @param string $db Database name
* @param string $host Host to connect
* @param string $user User (Auth)
* @param string $pwd Password (Auth)
*
* @return void
*/
final public static function connect($db, $host='localhost')
final public static function connect($db, $host='localhost', $user = null, $pwd=null)
{
self::$_host = $host;
self::$_db = $db;
self::$_user = $user;
self::$_pwd = $pwd;
}
// }}}

Expand Down Expand Up @@ -272,6 +290,14 @@ final protected function _getConnection()
if (!isSet(self::$_dbs[$dbname])) {
self::$_dbs[$dbname] = self::$_conn->selectDB($dbname);
}
if ( !is_null(self::$_user ) && !is_null(self::$_pwd ) ) {

self::$_dbs[$dbname]->authenticate( self::$_user,self::$_pwd ) ;


}


return self::$_dbs[$dbname];
}
// }}}
Expand Down

0 comments on commit 095418d

Please sign in to comment.