问题与mongodb php函数


Problems with mongodb php functions

我在php中实现mongoDB时遇到了几个问题

我的情况是,我做了一个函数,恢复mongoDB数据库在$_SESSION['mongoDb']变量,选择一个集合,然后使用函数find($where, $fields)

My error is

Fatal error: Call to a member function find() on a non-object in...

我试过检查mongodb php驱动程序和其他,但问题仍然存在…

编辑:更多关于。

感谢Eternal1的帖子,这有点令人困惑,因为相同的代码在生产服务器中工作,但不是我的本地主机XAMPP服务器。

问我密码的人,给你:

public function generic_select_mongo ($collection, $fields, $where, $order, $limit)
    {
    $mongoBd = $_SESSION['mongoBd'];
    $col = $mongoBd->$collection;
    $res = $col->find($where, $fields);
    $res->sort($order);
    $result = array();
    while ($docs = $res->getNext())
        {
        $result[] = $docs;
        }
    return $result;
    }

我将研究php中的Session。

MongoDB连接和其他DB连接一样,是resource类型的,不能序列化,因此不能正确地存储在会话中。PHP session manual:

某些类型的数据不能被序列化,因此存储在会话中。它包括具有循环引用的资源变量或对象。对象(将对自身的引用传递给另一个对象)

PHP会话