クライアントライブラリhttps://github.com/mongodb/mongo-php-library/blob/master/docs/tutorial/install-php-library.txtを使用してdrupalからmongoに接続しようとしています。 ソースコードをダウンロードしました。/MongoDBの(ライブラリのsrcフォルダ)drupalのMongo dbクライアントライブラリ7モジュール(作者なし)
--myModule.module
--myModule - 今私は
myModule
ディレクトリ構造の内部モジュール -
.moduleファイルでそれを使用したいです
function my_autoloader($class) {
print_r($class);
include DRUPAL_ROOT.'/sites/all/modules/myModule/MongoDB/' . $class . '.php';
}
spl_autoload_register('my_autoloader');
function myModule_init() {
//sample code to connect to mongo
$client = new MongoDB\Client("mongodb://xx.xx.xx.xx:27017");
$collection = $client->demo->beers;
$result = $collection->insertOne([ 'name' => 'Hinterland', 'brewery' => 'BrewDog' ]);
echo "Inserted with Object ID '{$result->getInsertedId()}'";
}
から
myModule.module
ファイル内
の.info
私は私が間違っているのは何のエラー
Fatal error: Class 'MongoDB\Client' not found
を取得しています。何か案が ???
注:私はこの
$m = new MongoDB\Driver\Manager("mongodb://xx.xxx.xx.xx:27017");
echo "Connection to database successfully";
を使用しようとすると接続できていますが、なぜクライアントを使用していません?
$ class = str_replace( '\\'、 '/'、$ class);を追加する必要がありました。 MongoDBをパス – NeiL
から削除してください。あなたの質問には解決してください。 – MilanG