window上安装 MongoDB PHP扩展

5 篇文章 0 订阅

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";
//        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值