Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
224 views
in Technique[技术] by (71.8m points)

php - how to solve fatal error : Uncaught Error?

I did REST API MONGODB-PHP CRUD via postman and got an uncaught error. I use XAMPP 3.2.2 PHP 7.2.1 are there any suggestion to fix it ?

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;
    }
}
?>

how i fix error ?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need rename

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

with

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

See here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...