The prerequisite for running the following program is that the MONGO extension is installed
<?php
Class Mongodbclass
{
Private $_mongo = null;
Public function __construct ($hostname, $hostport)
{
if (empty ($username)) {
$DSN = "mongodb://{$hostname}:{$hostport}";
}else{
$DSN = "mongodb://{$username}:{$password}@{$hostport}:{$hostport}";
}
$this->_mongo = new MONGO ($DSN);
}
Public Function GetVersion ()
{
$dbs = $this->_mongo->command (' function () {return db.version ();} ');
$ret = $this->_mongo->selectdb ("admin")->execute (' function () {return db.version ();} ');
return $ret;
}
}
$mongo = new Mongodbclass (' 192.168.1.230 ', 27017);
$dbs = $mongo->getversion ();
Print_r ($dbs);
?>
Through this sentence
$ret = $this->_mongo->selectdb ("admin")->execute (' function () {return db.version ();} ');
The same can be done under other MongoDB shell commands
Excerpt from: http://www.lofter.com/blog/fenglinyuye?act=dashboardclick_20130514_04