Class 'MongoClient' not found

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

I\'m trying to make this code run:

tilbud; 

?>

Everytime I g

相关标签:
7条回答
  • 2020-11-28 10:07

    For those arriving on this page with PHP 7 installed:

    The MongoCLient class was provided by pecl install mongo. But pecl/mongo is not available for php7 and deprecated in favor of pecl/mongodb. But with pecl/mongodb you'll need to use MongoDB\Driver\Manager instead of MongoClient (warning on page says so too).

    See here for further reading.

    This said, you will need an abstraction layer on top of the PHP MongoDB\Driver\Manager. This is provided by mongodb/mongo-php-library.

    You will need to refactor stuff like:

    • \MongoClient to \MongoDB\Client
    • \MongoCollection to \MongoDB\Collection
    • \MongoClient->selectDB to \MongoDB\Client->selectDatabase
    • \MongoClient->listDBs to \MongoDB\Client->listDatabases
      • also output is not an array but an iterator, so you'll need to use iterator_to_array, along with edits to how you use the resulting object
    • \MongoCollection->getName to \MongoDB\Collection->getCollectionName
    • \MongoCollection->update to \MongoDB\Collection->updateOne or updateMany
    • \MongoCollection->remove to \MongoDB\Collection->deleteOne
    • \MongoCollection->batchInsert to \MongoDB\Collection->insertMany
    0 讨论(0)
提交回复
热议问题