当前位置:Gxlcms > 数据库问题 > 安装mongodb插件

安装mongodb插件

时间:2021-07-01 10:21:17 帮助过:14人阅读

1、安装mngodb模块

wget http://pecl.php.net/get/mongodb-1.2.4.tgz
tar zxf mongodb-1.2.4.tgz
cd mongodb-1.2.4
/application/php/bin/phpize 
./configure --with-php-config=/application/php/bin/php-config
make
make install
  Installing shared extensions:     /application/php-7.1.7/lib/php/extensions/no-debug-non-zts-20160303/

2、检查模块是否存在

cd /application/php-7.1.7/lib/php/extensions/no-debug-non-zts-20160303/
ls mongodb.so 
  mongodb.so

3、修改 php.ini

vim /application/php/lib/php.ini
 ...
 extension=redis.so    #添加此行
 ...

4、重启php-fpm

5、测试连接mongodb,访问页面正常,表示连接成功

<?php
$manager = new MongoDB\Driver\Manager("mongodb://127.0.0.1:27017");
$bulk = new MongoDB\Driver\BulkWrite;
$bulk->insert([‘x‘ => 1, ‘class‘=>‘toefl‘, ‘num‘ => ‘18‘]);
$bulk->insert([‘x‘ => 2, ‘class‘=>‘ielts‘, ‘num‘ => ‘26‘]);
$bulk->insert([‘x‘ => 3, ‘class‘=>‘sat‘, ‘num‘ => ‘35‘]);
$manager->executeBulkWrite(‘test.log‘, $bulk);
$filter = [‘x‘ => [‘$gt‘ => 1]];
$options = [
    ‘projection‘ => [‘_id‘ => 0],
    ‘sort‘ => [‘x‘ => -1],
];
$query = new MongoDB\Driver\Query($filter, $options);
$cursor = $manager->executeQuery(‘test.log‘, $query);
foreach ($cursor as $document) {
    print_r($document);
}

  

 

 

 

  

 

安装mongodb插件

标签:class   filter   app   php-fpm   安装   测试   test   get   highlight   

人气教程排行