首页 > 数据库技术 > 详细

安装mongodb插件

时间:2017-11-05 17:49:05      阅读:215      评论:0      收藏:0      [点我收藏+]

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插件

原文:http://www.cnblogs.com/sellsa/p/7787991.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!