Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-06-13 08:38:04
Original
1147 people have browsed it

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

本文实例讲述了PHP简单操作MongoDB的方法。分享给大家供大家参考,具体如下:

php操作MongoDB的话首先从网上下载MongoDB的扩展包,https://github.com/mongodb/mongo-php-driver/downloads,选择对应的扩展包。

这是我下的,然后解压,VC6适合apache,VC9适合IIS,ts(thread safe)指PHP以模块形式运行的。

然后把其中的php_mongo.dll放在PHP中的ext文件夹中,然后在PHP.INI里面加入extension=php_mongo.dll,重启apache。

至此PHP扩展MongoDB的包安装完毕。

关于查询MongoDB一些使用函数可以查询手册http://us.php.net/manual/en/class.mongocollection.php

<&#63;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")));
*/
&#63;>

Copy after login

更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP+MongoDB数据库操作技巧大全》、《PHP基于pdo操作数据库技巧总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!