Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Mongodb连接不工作_Php_Mongodb - Fatal编程技术网

Php Mongodb连接不工作

Php Mongodb连接不工作,php,mongodb,Php,Mongodb,您好,我在这方面遇到了一些问题。请帮帮我 我的代码如下所示: session_start(); $GLOBALS["config"] =array( "mongodb"=> array( "host"=> "127.0.0.1","username"=>"root", "password"=>"","db"=>"lr"),"remember"=> array( "cookie_name"=>"shoeib", "cookie_expire"=> 6

您好,我在这方面遇到了一些问题。请帮帮我

我的代码如下所示:

session_start(); $GLOBALS["config"] =array( "mongodb"=> array( "host"=> "127.0.0.1","username"=>"root", "password"=>"","db"=>"lr"),"remember"=> array( "cookie_name"=>"shoeib", "cookie_expire"=> 604800 ),
"session"=> array( "session_name"=>"users") );
spl_autoload_register(function($class) { require_once"classes/" . $class.".php"; }); require_once "functions/sanitize.php"; 
这是我仅创建db的数据库

class db{



private static $_instance= null;
private $_pdo,
$_query,
$_error= FALSE,
$_result,
$_count= 0;

public function __construct(){ try { $this->$connection = new Mongoclient("mongoclient:host".config::get ("mongodb/host").";dbname=".config::get("mongodb/db"),config::get("mongodb/username"),config::get ("mongodb/password"));$this->database = $this->connection-> selectDB(DBConnection::DBNAME);} catch (MongoConnectionException $e)throw $e; } }public static function getInstance(){ if (!isset(self::$instance)) { self::$instance = new db;} return self::$instance;}

公共函数getCollection($name){return$this->database->selectCollection($name);}

您将db类结束在错误的行上,请尝试以下操作

class db
{

    private static $_instance = null;
    private $_pdo,
        $_query,
        $_error = FALSE,
        $_result,
        $_count = 0;

    public function __construct()
    {
        try {
            $this->$connection = new Mongoclient("mongoclient:host" . config::get("mongodb/host") . ";dbname=" . config::get("mongodb/db"), config::get("mongodb/username"), config::get("mongodb/password"));
            $this->database = $this->connection->selectDB(DBConnection::DBNAME);
        } catch (MongoConnectionException $e)throw $e;
    }

    public static function getInstance()
    {
        if (!isset(self::$instance)) {
            self::$instance = new db;
        }
        return self::$instance;
    }
    public function getCollection($name)
    {
        return $this->database->selectCollection($name);
    }
}
您的MongoClient用法似乎不正确,但我可能错了


另请查看

请格式化您的代码,使其更具可读性。还有,不清楚你的问题是什么?MongoDB正在运行吗?如果他们以前没有使用过服务/守护进程/进程,很多人会忘记实际启动它。你能给我正确的答案吗?这样我就可以写了!您没有解决格式问题,也没有澄清您的问题是什么。MongoDB正在运行吗?我正在尝试在一个页面上建立MongoDB连接以连接我的所有页面基本上我想要一个MongoDB页面!感叹号是必要的吗?MongoDb正在运行吗?我已经问过好几次了。
public MongoClient::__construct() ([ string $server = "mongodb://localhost:27017" [, array $options = array("connect" => TRUE) ]] )