编译安装PHP7
编译安装PHP7 Mongdb扩展
#先安装一个依赖库yum -y install openldap-develwget https://pecl.php.net/get/mongodb-1.1.1.tgz /home/server/php7/bin/phpize #根据自己编译的PHP环境而定./configure --with-php-config=/home/server/php7/bin/php-config make && make install#如果成功,生成一个mongodb.so扩展在lib/php/extensions/no-debug-non-zts-20151012/修改php.ini配置extension=mongodb.so
注:
以前版本用的是mongo.so扩展,老的php-mongodb api
在PHP7已经不支持了,至少目前不支持。
最新支持PHP7的mongodb 编译后 仅支持新版API(mongodb > 2.6.X版本)
参考资料
GITHUB: https://github.com/mongodb/
官网:
http://www.mongodb.org/
PHP官方: https://pecl.php.net/package/mongodb http://pecl.php.net/package/mongo [已废弃,目前只支持到PHP5.9999]
API手册:http://docs.php.net/manual/en/set.mongodb.php
Mongodb API 操作
初始化Mongodb连接
$manager = new MongoDB/Driver/Manager("mongodb://127.0.0.1:27017"); var_dump($manager); object(MongoDB/Driver/Manager)#1 (3) { ["request_id"]=> int(1714636915) ["uri"]=> string(25) "mongodb://localhost:27017" ["cluster"]=> array(13) { ["mode"]=> string(6) "direct" ["state"]=> string(4) "born" ["request_id"]=> int(0) ["sockettimeoutms"]=> int(300000) ["last_reconnect"]=> int(0) ["uri"]=> string(25) "mongodb://localhost:27017" ["requires_auth"]=> int(0) ["nodes"]=> array(...) ["max_bson_size"]=> int(16777216) ["max_msg_size"]=> int(50331648) ["sec_latency_ms"]=> int(15) ["peers"]=> array(0) { } ["replSet"]=> NULL }}
CURL操作
$bulk = new MongoDB/Driver/BulkWrite(['ordered' => true]);$bulk->delete([]); $bulk->insert(['_id' => 1]); $bulk->insert(['_id' => 2]); $bulk->insert(['_id' => 3, 'hello' => 'world']);$bulk->update(['_id' => 3], ['$set' => ['hello' => 'earth']]); $bulk->insert(['_id' => 4, 'hello' => 'pluto']); $bulk->update(['_id' => 4], ['$set' => ['hello' => 'moon']]); $bulk->insert(['_id' => 3]); $bulk->insert(['_id' => 4]); $bulk->insert(['_id' => 5]); $manager = new MongoDB/Driver/Manager('mongodb://localhost:27017'); $writeConcern = new MongoDB/Driver/WriteConcern(MongoDB/Driver/WriteConcern::MAJORITY, 1000); try { $result = $manager->executeBulkWrite('db.collection', $bulk, $writeConcern); } catch (MongoDB/Driver/Exception/BulkWriteException $e) { $result = $e->getWriteResult(); // Check if the write concern could not be fulfilled if ($writeConcernError = $result->getWriteConcernError()) {printf("%s (%d): %s/n", $writeConcernError->getMessage(), $writeConcernError->getCode(), var_export($writeConcernError->getInfo(), true)); } // Check if any write operations did not complete at all foreach ($result->getWriteErrors() as $writeError) {printf("Operation#%d: %s (%d)/n", $writeError->getIndex(), $writeError->getMessage(), $writeError->getCode()); }} catch (MongoDB/Driver/Exception/Exception $e) { printf("Other error: %s/n", $e->getMessage()); exit;}printf("Inserted %d document(s)/n", $result->getInsertedCount()); printf("Updated %d document(s)/n", $result->getModifiedCount());
查询
$filter = array();$options = array( /* Only return the following fields in the matching documents */ "projection" => array("title" => 1,"article" => 1, ), "sort" => array("views" => -1, ), "modifiers" => array('$comment' => "This is a query comment",'$maxTimeMS' => 100, ),);$query = new MongoDB/Driver/Query($filter, $options);$manager = new MongoDB/Driver/Manager("mongodb://localhost:27017"); $readPreference = new MongoDB/Driver/ReadPreference(MongoDB/Driver/ReadPreference::RP_PRIMARY);$cursor = $manager->executeQuery("databaseName.collectionName", $query, $readPreference); foreach($cursor as $document) { var_dump($document);}
以上内容是小编给大家分享的PHP7之Mongodb API使用详解,希望大家喜欢。
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
- 雨林唱片《赏》新曲+精选集SACD版[ISO][2.3G]
- 罗大佑与OK男女合唱团.1995-再会吧!素兰【音乐工厂】【WAV+CUE】
- 草蜢.1993-宝贝对不起(国)【宝丽金】【WAV+CUE】
- 杨培安.2009-抒·情(EP)【擎天娱乐】【WAV+CUE】
- 周慧敏《EndlessDream》[WAV+CUE]
- 彭芳《纯色角3》2007[WAV+CUE]
- 江志丰2008-今生为你[豪记][WAV+CUE]
- 罗大佑1994《恋曲2000》音乐工厂[WAV+CUE][1G]
- 群星《一首歌一个故事》赵英俊某些作品重唱企划[FLAC分轨][1G]
- 群星《网易云英文歌曲播放量TOP100》[MP3][1G]
- 方大同.2024-梦想家TheDreamer【赋音乐】【FLAC分轨】
- 李慧珍.2007-爱死了【华谊兄弟】【WAV+CUE】
- 王大文.2019-国际太空站【环球】【FLAC分轨】
- 群星《2022超好听的十倍音质网络歌曲(163)》U盘音乐[WAV分轨][1.1G]
- 童丽《啼笑姻缘》头版限量编号24K金碟[低速原抓WAV+CUE][1.1G]