当前位置:网站首页>About PHP startup, mongodb cannot find the specified module
About PHP startup, mongodb cannot find the specified module
2022-07-06 05:54:00 【Beiqiaosu】
Preface :
Recently, there is a little demo, Need to pass through PHP Store user behavior records in MongoDB, Reuse Spark Do collaborative filtering . Because in the past, cross language interaction was handled through message oriented middleware , This time it is used locally MongoDB But it caused several problems . First, the extension is installed locally , The startup times cannot find the module error , Another hour PHP The instantiation times MongoClient And some functions do not exist . Finally, I also recommend some convenient and fast MongoDB Graphic tool .
Environmental Science :
1. Windows10
2. PHP7.4
3. MongoDB 4.4.14 Server
5. php_mongodb-1.12.1-7.4-nts-vc15-x64
install :
2. php_mongodb-1.12.1-7.4-nts-vc15-x64 download
3. navicat for mongodb download
problem :
1. Specified module not found php_mongodb
PHP Add extension to php_mongodb Incorrect , Except for the need to php_mongodb.dll still more php_mongodb.pdb Copied to the php Install under directory ext in
Last in php.ini add to extension=php_mongodb.dll, After restarting, view php -m Or view in the browser phpinfo ()
2. MongoClient Class does not exist
The reason is that this is an old version php_mongo Extend the provided classes , The new version is through the way of demonstrating the code later , If you don't know the new methods or functions provided by the extension, you can view them in the following ways .
(1). get_declared_classes () Check the preset functions in the extension
Tool use :
1. MongoDB Server
(1). Start the service
2. Navicat for MongoDB
(1). Connection service
Code demonstration :
1. Inquire about
public function testMongoDbQuery()
{
$manager = new \MongoDB\Driver\Manager("mongodb://localhost:27017");
$filter = ['x' => ['$gt' => 0]];
$options = [
'projection' => ['_id' => 0],
'sort' => ['x' => -1],
];
// Query data
$query = new \MongoDB\Driver\Query($filter, $options);
$cursor = $manager->executeQuery('test.sites', $query);
foreach ($cursor as $document) {
print_r($document);
}
}
2. Insert
public function testMongoDbInsert()
{
$manager = new \MongoDB\Driver\Manager("mongodb://localhost:27017");
$bulk = new \MongoDB\Driver\BulkWrite;
// mongoDb By default, there is a self growing string ID
$document = [
'_id' => new \MongoDB\BSON\ObjectID,
'videoId' => mt_rand(1, 99999),
'userId' => mt_rand(1, 9999),
'score' => floatval(mt_rand(5,100)),
'date' => time()
];
$bulk->insert($document);
$res = $manager->executeBulkWrite('tanhua.recommend_video_20191001', $bulk);
return $res;
}
3. Batch insert
public function testMongoDbBulk()
{
//return get_declared_classes();
$manager = new \MongoDB\Driver\Manager("mongodb://localhost:27017");
$bulk = new \MongoDB\Driver\BulkWrite;
$bulk->insert(['x' => 1, 'name'=>'tenent', 'url' => 'http://www.runoob.com']);
$bulk->insert(['x' => 2, 'name'=>'Google', 'url' => 'http://www.google.com']);
$bulk->insert(['x' => 3, 'name'=>'taobao', 'url' => 'http://www.taobao.com']);
$res = $manager->executeBulkWrite('test.sites', $bulk);
return $res;
}
Exchange of learning
边栏推荐
- B站刘二大人-线性回归 Pytorch
- Redis6 cluster setup
- Is it difficult for an information system project manager?
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- AUTOSAR从入门到精通番外篇(十)-嵌入式S19文件解析
- LAN communication process in the same network segment
- Wib3.0 leapfrogging, in leapfrogging (ง • ̀_•́) ง
- [force buckle]43 String multiplication
- continue和break的区别与用法
- [Jiudu OJ 07] folding basket
猜你喜欢
LAN communication process in the same network segment
Station B, Master Liu Er - back propagation
C language learning notes (mind map)
B站刘二大人-线性回归 Pytorch
HCIA复习
(column 22) typical column questions of C language: delete the specified letters in the string.
wib3.0 跨越,在跨越(ง •̀_•́)ง
实践分享:如何安全快速地从 Centos迁移到openEuler
c语言——冒泡排序
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
随机推荐
[Baiwen smart home] first day of the course_ Learn Embedded and understand the development mode of bare metal and RTOS
H3C S5820V2_5830V2交换机IRF2堆叠后升级方法
查詢生產訂單中某個(些)工作中心對應的標准文本碼
continue和break的区别与用法
Processes and threads
59. Spiral matrix
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
How Huawei routers configure static routes
Game push: image / table /cv/nlp, multi-threaded start!
Title 1093: character reverse order
[paper reading] nflowjs: synthetic negative data intensive anomaly detection based on robust learning
Pay attention to the details of pytoch code, and it is easy to make mistakes
P2802 回家
Auto.js学习笔记17:基础监听事件和UI简单的点击事件操作
Market development prospect and investment risk assessment report of China's humidity sensor industry from 2022 to 2028
YYGH-11-定时统计
A master in the field of software architecture -- Reading Notes of the beauty of Architecture
网站进行服务器迁移前应做好哪些准备?
AUTOSAR from getting started to becoming proficient (10) - embedded S19 file analysis
Auto. JS learning notes 17: basic listening events and UI simple click event operations