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
<?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相关内容感兴趣的读者可查看本站专题:《PHP+MongoDB数据库操作技巧大全》、《PHP基于pdo操作数据库技巧总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft