简体   繁体   中英

PHP: class “MongoClient” not found?

I have this problem when i try to do app/console doctrine:mongodb:schema:update on the terminal :

[Symfony\\Component\\Debug\\Exception\\ClassNotFoundException] Attempted to load class "MongoClient" from the global namespace. Did you forget a "use" statement?

I tried everything I found. Anyone can help me please?

I can see you're using Doctrine MongoDB ODM. Doctrine MongoDB ODM relies on legacy mongo driver ext-mongo , that is available only to PHP up to 5.6. If you're using PHP up to 5.6 you just have to install and enable it.

If you're using PHP7+ you have to install the new mongo driver ext-mongodb and use a polyfill to bridge the Doctrine MongoDB ODM with the new library, as stated here: http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/introduction.html#using-php-7

You can use Doctrine MongoDB ODM with PHP 7, but there are a few extra steps during the installation. Since the legacy driver (referred to as ext-mongo) is not available on PHP 7, you will need the new driver (ext-mongodb) installed and use a polyfill to provide the API of the legacy driver.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM