window上安装 MongoDB PHP扩展
1、下载扩展
2、引入扩展
3、查看是否安装成功
4、安装查看界面工具
安装成功后,连接成功后打开界面为:
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";
// }