【问题标题】:how to solve fatal error : Uncaught Error?如何解决致命错误:未捕获的错误?
【发布时间】:2020-12-30 19:53:26
【问题描述】:

我通过邮递员执行了 REST API MONGODB-PHP CRUD 并得到了一个未捕获的错误。我使用 XAMPP 3.2.2 PHP 7.2.1 有什么建议可以解决吗?

db.php

<?php
class DbManager {

    //Database configuration
    private $dbhost = 'localhost';
    private $dbport = '27017';
    private $conn;

    function __construct(){
        //Connecting to MongoDB
        try{
            //Establish database connection
            $this->conn = new MongoDBDriverManager('mongodb://'.$this->dbhost.':'.$this->dbport);
        }catch (MongoDBDriverExceptionException $e) {
            echo $e->getMessage();
            echo nl2br("n");
        }
    }

    function getConnection() {
        return $this->conn;
    }
}
?>

如何修复错误?

<br />
<b>Fatal error</b>:  Uncaught Error: Class 'MongoDBDriverManager' not found in C:\xampp\htdocs\mongo\db.php: 13
Stack trace:
#0 C:\xampp\htdocs\mongo\create.php(17): DbManager-&gt;__construct()
#1 {main
}
  thrown in <b>C:\xampp\htdocs\mongo\db.php</b> on line <b>13</b><br />

【问题讨论】:

    标签: php mongodb xampp postman


    【解决方案1】:

    你需要重命名

    $this->conn = new MongoDBDriverManager('mongodb://'.$this->dbhost.':'.$this->dbport);
    

    $this->conn = new MongoDB\Driver\Manager('mongodb://'.$this->dbhost.':'.$this->dbport);
    

    here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-28
      • 2020-07-28
      • 1970-01-01
      • 2019-04-20
      • 2019-01-11
      • 2020-01-31
      • 2019-09-21
      相关资源
      最近更新 更多