dongqidi2799 2019-04-19 18:44
浏览 49

文档不使用php插入

I am trying to insert a document using PHP for my project but the code is not working.

for reference, I have echoed "still here" and "done".

But the code is not able to execute the insert query please help.

I have already tried all the stack overflow and other sites but non of them work properly.

<?php

   require 'vendor/autoload.php';
   include 'lib/JSON.php';

   // connect to mongodb
   $client = new MongoDB\Client("mongodb://localhost:27017");

   // select a database
   $db = $client->hm;
   $collection = $db->sc;
   $count = $collection->count();

   $document = array("_id" => $count,
          "device_id" => 100,
          "pin" => 17,
          "status" => "True");  

   echo "still here";
   $collection->insert($document);
   echo "done"
?>

I am only getting "still here" on browser.

  • 写回答

1条回答 默认 最新

  • dsfsdfsd34324 2019-04-20 05:09
    关注

    Try to use method insertOne. Does that give some additional errors?

    https://docs.mongodb.com/php-library/master/reference/method/MongoDBCollection-insertOne/

    评论

报告相同问题?

悬赏问题

  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计