window上安装 MongoDB PHP扩展

本文详细介绍了在Windows环境下安装MongoDB PHP扩展的过程,并提供了Robomongo界面工具的使用指南。通过具体代码示例,展示了如何利用PHP进行MongoDB数据库的基本操作,包括增删改查。

window上安装 MongoDB PHP扩展

1、下载扩展

下载对应的版本 http://pecl.php.net/package/mongo

在这里插入图片描述
2、引入扩展
在这里插入图片描述

3、查看是否安装成功
在这里插入图片描述

4、安装查看界面工具

https://robomongo.org/

安装成功后,连接成功后打开界面为:
在这里插入图片描述

5、代码编写

$m = new MongoClient();
        $db = $m->mytestdb;             //选择数据库,没有则会新建

//        $collection = $db->createCollection("mycol");   //新增一个集合
        $collection = $db->mycol;      // 选择集合

        #增
//        $document = array(
//            "title" => "MongoDB",
//            "description" => "database",
//            "likes" => 100,
//            "url" => "http://www.runoob.com/mongodb/",
//            "by"=>"菜鸟教程"
//        );
//        $collection->insert($document);

        #查
//        $cursor = $collection->find();
//        // 迭代显示文档标题
//        foreach ($cursor as $document) {
//            var_dump($document);
//        }

        #改
//        $collection->update(array("title"=>"MongoDB"), array('$set'=>array("title"=>"MongoDB 教程")));   #更新第一条
//        // 显示更新后的文档
//        $cursor = $collection->find();
//        // 循环显示文档标题
//        foreach ($cursor as $document) {
//            echo $document["title"] . "\n";
//        }

        #删
//        $collection->remove(array("title"=>"MongoDB 教程"), array("justOne" => true));
//
//        // 显示可用文档数据
//        $cursor = $collection->find();
//        foreach ($cursor as $document) {
//            echo $document["title"] . "\n";
//        }
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值