클라이언트 라이브러리 https://github.com/mongodb/mongo-php-library/blob/master/docs/tutorial/install-php-library.txt을 사용하여 drupal에서 mongo에 연결하려고합니다. 소스 코드를 다운로드했습니다./MongoDB를 (라이브러리의 src 폴더)mongo db client library in drupal 작성자가없는 모듈
--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);를 추가해야했습니다. 그리고 – NeiL
에서 MongoDB를 제거한 다음 질문을 해결하시기 바랍니다. – MilanG