2016-04-14 15:12
浏览 84


I've installed the mongodb driver (php_mongodb.dll). The file is inside xampp\php\ext. I've used it before with simple connections and queries against my mongodb server and it works perfectly.

To make the connection with mongo I use this simple line:

$conn = new MongoDB\Driver\Manager("mongodb://localhost:27017");

However, when I try to use it in my symfony project, I get this error:

Attempted to load class "Manager" from namespace "AlimentosBundle\Controller\MongoDB\Driver". Did you forget a "use" statement for another namespace?

I'm very beginner using symfony. Should I import also the DLL inside the symfony project? If not, how could I force Symfony to find the DLL?

I know that doctrine/mongodb bundle actually exists, but I just wanted to try some simple connections, is possible to do it without that bundle?

图片转代码服务由CSDN问答提供 功能建议

我安装了mongodb驱动程序( php_mongodb.dll )。 该文件位于 xampp \ php \ ext 中。 我之前使用过简单的连接和对我的mongodb服务器的查询,它运行得很好。

要与mongo建立连接我使用这个简单的行: \ n

$ conn = new MongoDB \ Driver \ Manager(“mongodb:// localhost:27017”);

但是,当我尝试使用时 在我的symfony项目中,我收到此错误:

尝试从命名空间“AlimentosBundle \ Controller \ MongoDB \ Driver”加载类“Manager”。 你有没有 忘记另一个名称空间的“use”语句?

我是初学者,使用symfony。 我应该在symfony项目中导入DLL吗? 如果没有,我怎么能强迫Symfony找到DLL?

我知道doctrine / mongodb包实际存在,但我只是想尝试一些简单的连接,可以不用 那捆?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dps69208 2016-04-14 15:23

    You miss an initial slash. Try this:

    $conn = new \MongoDB\Driver\Manager("mongodb://localhost:27017");

    instead of:

    $conn = new MongoDB\Driver\Manager("mongodb://localhost:27017");

    Obviously, as suggested, you can import the class and use without the namespace, as example:

    use  MongoDB\Driver\Manager;
    $conn = Manager("mongodb://localhost:27017");

    Hope this help

    解决 无用
    打赏 举报

相关推荐 更多相似问题