php7使用MongoDB
来源:互联网 发布:纯网络综艺节目 编辑:程序博客网 时间:2024/04/28 20:25
安装
打开网址: https://pecl.php.net/package/mongodb
选择适合自己的版本
打开php.ini 添加
extension=php_mongodb.dll
查看是否安装成功
php -m|findstr mongodbmongodb
写个测试例子
php7需要使用全新的api跟之前版本不一样
$bulk = new MongoDB\Driver\BulkWrite();$bulk->insert(['_id' => 1, 'x' => 1]);$bulk->insert(['_id' => 2, 'x' => 2]);$bulk->update(['x' => 2], ['$set' => ['x' => 1]], ['multi' => false, 'upsert' => false]);$bulk->update(['x' => 3], ['$set' => ['x' => 3]], ['multi' => false, 'upsert' => true]);$bulk->update(['_id' => 3], ['$set' => ['x' => 3]], ['multi' => false, 'upsert' => true]);$bulk->insert(['_id' => 4, 'x' => 2]);$bulk->delete(['x' => 1], ['limit' => 1]);$manager = new MongoDB\Driver\Manager('mongodb://localhost:27017');$writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 100);$result = $manager->executeBulkWrite('db.test', $bulk, $writeConcern);printf("Inserted %d document(s)\n", $result->getInsertedCount());printf("Matched %d document(s)\n", $result->getMatchedCount());printf("Updated %d document(s)\n", $result->getModifiedCount());printf("Upserted %d document(s)\n", $result->getUpsertedCount());printf("Deleted %d document(s)\n", $result->getDeletedCount());foreach ($result->getUpsertedIds() as $index => $id) { printf('upsertedId[%d]: ', $index); var_dump($id);}/* If the WriteConcern could not be fulfilled */if ($writeConcernError = $result->getWriteConcernError()) { printf("%s (%d): %s\n", $writeConcernError->getMessage(), $writeConcernError->getCode(), var_export($writeConcernError->getInfo(), true));}
阅读全文
0 0
- PHP7:Mongodb API使用
- php7使用MongoDB
- PHP7之Mongodb API使用详解
- Mac下面的MAMP-php7使用mongodb
- php7 mongoDB 简单封装
- php7安装mongoDB扩展
- php7安装mongoDB扩展
- PHP7 操作MongoDB
- ubuntu 安装php7 mongodb扩展
- PHP7 连接 MongoDB 语法如下
- php7.0操作mongodb数据库
- windows php7 安装 mongodb 扩展
- windows php7 安装 mongodb 扩展
- windows php7 安装 mongodb 扩展
- php7中使用mongoDB的聚合操作对数据进行分组求和统计操作
- PHP7使用Memcached
- UBUNTU中搭建 APACHE2 + PHP7 + MONGODB + REDIS
- 安装PHP7以及MongoDB的扩展
- HDOJ1394 求逆序对
- 第五周——项目三
- myEclipse中使用maven插件新建maven项目
- 网络数据连接数据库
- 【慕课网_性能优化之MySQL优化_学习】【04】
- php7使用MongoDB
- 第九周项目二-二叉树遍历的递归算法
- 第九周项目2二叉树遍历的递归算法
- 第八周项目二(4) 获取公共子串
- Spring-boot
- HDFS的体系架构
- Best Time to Buy and Sell Stock
- ijkplayer从编译到使用来播放rtsp过程小结
- python运算实践