windows上安装mongodb的php扩展
下载地址https://s3.amazonaws.com/drivers.mongodb.org/php/index.html
找到对应的php版本的dll文件,下载php_mongo.dll
,放到php安装目录下的ext目录中,修改php.ini,添加一项extension=php_mongo.dll
,没有找到支持php7的dll
<?php // 连接到mongodb $mongoClient = new MongoClient(); // 选择一个数据库 $db = $mongoClient->test; //获取集合 $collection=$db->users; //更新文档 $condition=array(); $condition["id"]=1; $data=array(); $data['name']="wangwu"; $data['age']="11"; $collection->update($condition,$data); //插入文档 $data=array(); $data['id']=4; $data['name']="哈哈"; $data['age']="11"; $collection->insert($data); //删除文档 $condition=array(); $condition['id']=2; $collection->remove($condition); //查询文档 $users=$collection->find(); foreach ($users as $k => $v) { print_r($v); } ?>