Class 'MongoClient' not found

前端 未结 7 1817
灰色年华
灰色年华 2020-11-28 09:19

I\'m trying to make this code run:

tilbud; 

?>

Everytime I g

相关标签:
7条回答
  • 2020-11-28 09:45

    your php version and dll file version should be same check it if versions are not same then update your xampp php according to the available dll version.

    0 讨论(0)
  • 2020-11-28 09:47

    Getting the same error and now it's solved.
    I am using Linux Mint. To solve this issue I added extension=mongo.so in two directories:

    • /etc/php5/cli/php.ini
    • /etc/php5/apache2/php.ini
    0 讨论(0)
  • 2020-11-28 09:52

    From this page:

    Note: Additional DLL dependencies for Windows Users:

    In order for this extension to work, there are DLL files that must be available to the Windows system PATH

    0 讨论(0)
  • 2020-11-28 09:55

    You have not installed MongoDB PHP driver please see this link http://www.php.net/manual/en/mongo.installation.php

    Update sources

    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
    echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
    sudo apt-get update
    

    Install MongoDB PHP Driver

    sudo apt-get install php5-dev php5-cli php-pear -y
    sudo pecl install mongo
    

    Open your php.ini file and add to it:

    extension=mongo.so
    

    Restart apache

    sudo /etc/init.d/apache2 restart
    

    Other helping info:

    this should help to find your php.ini file:

    php -i | grep 'Configuration File'
    

    On Ubuntu it shows this:

    Configuration File (php.ini) Path => /etc/php5/cli
    Loaded Configuration File => /etc/php5/cli/php.ini
    

    take a note, that you run this command from cli (command line) so for your true php.ini go to folder apache2 instead of cli :)

    0 讨论(0)
  • 2020-11-28 10:00

    The answer is indeed to follow the instructions. I was missing the very important require line that must come before creating the new mongodb object:

    <?php
    
    require 'vendor/autoload.php';
    
    $client = new MongoDB\Client("mongodb://localhost:27017");
    

    And of course you need to run this command in the root of your project as per the instructions:

    composer require mongodb/mongodb
    
    0 讨论(0)
  • 2020-11-28 10:03

    install the driver, I have for example php5.6:

    sudo apt-get install php5.6-mongo
    
    0 讨论(0)
提交回复
热议问题