安装mongodb插件

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);
}

  

 

 

 

  

 

posted @ 2017-11-05 17:38  sellsa  阅读(702)  评论(0编辑  收藏  举报