您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

PHP7之Mongodb API使用详解,_PHP教程

2024/4/17 16:48:36发布5次查看
php7之mongodb api使用详解,编译安装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使用详解,希望大家喜欢。
您可能感兴趣的文章:php对mongodb的扩展(初出茅庐)php对mongodb的扩展(初识如故)php对mongodb[nosql]数据库的操作php操作mongodb基础教程(连接、新增、修改、删除、查询)php实现的mongodb数据库操作类分享高效mongodb的php分页类(不使用skip)thinkphp使用mongodb数据库实现多条件查询方法php中mongodb数据库的连接、添加、修改、查询、删除等操作实例centos yum 安装 mongodb 以及php扩展php中的mongodb group操作实例迁移php版本到php7php实现mongodb自定义方式生成自增id的方法php7.0版本备注php7.0安装笔记整理浅谈php7的重大新特性php7正式版测试,性能惊艳!
http://www.bkjia.com/phpjc/1084515.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/1084515.htmltecharticlephp7之mongodb api使用详解, 编译安装php7 编译安装php7 mongdb扩展 #先安装一个依赖库yum -y install openldap-develwget https://pecl.php.net/get/mongodb-1.1.1.t...
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录