源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

PHP简单操作MongoDB的方法(安装及增删改查)

  • 时间:2020-03-24 08:23 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:PHP简单操作MongoDB的方法(安装及增删改查)
本文实例讲述了PHP简单操作MongoDB的方法。分享给大家供大家参考,具体如下: php操作MongoDB的话首先从网上下载MongoDB的扩展包,[url=https://github.com/mongodb/mongo-php-driver/downloads]https://github.com/mongodb/mongo-php-driver/downloads[/url],选择对应的扩展包。 [img]http://files.jb51.net/file_images/article/201605/201652690312438.png?20164269337[/img] 这是我下的,然后解压,VC6适合apache,VC9适合IIS,ts(thread safe)指PHP以模块形式运行的。 [img]http://files.jb51.net/file_images/article/201605/201652690341693.png?2016426945[/img] 然后把其中的php_mongo.dll放在PHP中的ext文件夹中,然后在PHP.INI里面加入extension=php_mongo.dll,重启apache。 至此PHP扩展MongoDB的包安装完毕。 关于查询MongoDB一些使用函数可以查询手册[url=http://us.php.net/manual/en/class.mongocollection.php]http://us.php.net/manual/en/class.mongocollection.php[/url]
<?php
error_reporting(7);
$conn = new Mongo();
$db = $conn->PHPDataBase;
$collection = $db->PHPCollection;
/*-----------------------------
 * 删除
 *-----------------------------
$collection->remove(array("name" => "xixi111"));
*/
/*------------------------------
 * 插入
 *------------------------------
for($i = 0;$i <= 50;$i++) {
  $data = array("name" => "xixi".$i,"email" => "673048143_".$i."@qq.com","age" => $i*1+20);
  $collection->insert($data);
}
*/
/*-------------------------------
 * 查找
 *-------------------------------
$res = $collection->find(array("age" => array('$gt' => 25,'$lt' => 40)),array("name" => true));
foreach($res as $v) {
  print_r($v);
}
*/
/*-------------------------------
 * 更新
 *-------------------------------
 $collection->update(array("age" =>22),array('$set' => array("name" => "demoxixi")));
*/
?>

更多关于PHP相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/586.htm]PHP+MongoDB数据库操作技巧大全[/url]》、《[url=http://www.1sucai.cn/Special/192.htm]PHP基于pdo操作数据库技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/43.htm]php面向对象程序设计入门教程[/url]》、《[url=http://www.1sucai.cn/Special/47.htm]php字符串(string)用法总结[/url]》、《[url=http://www.1sucai.cn/Special/84.htm]php+mysql数据库操作入门教程[/url]》及《[url=http://www.1sucai.cn/Special/231.htm]php常见数据库操作技巧汇总[/url]》 希望本文所述对大家PHP程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部