PHP链接mongodb数据库并进行增删查改的例子,如下:[php]PHP连接MongoDB示例: selectDB("comedy");$db = $m->comedy;//选择comedy里面的collection集合,相当于RDBMS里面的表,也-可以使用$collection = $db->collection;$db->selectCollection("collection");//添加一个元素$obj = array( "title" => "Calvin and Hobbes-".date('i:s'), "author" => "Bill Watterson" );//将$obj 添加到$collection 集合中$collection->insert($obj);//添加另一个元素$obj = array( "title" => "XKCD-".date('i:s'), "online" => true );$collection->insert($obj);//查询所有的记录$cursor = $collection->find();//遍历所有集合中的文档foreach ($cursor as $obj){echo $obj["title"] . "\n";}//删除所有数据$collection->remove();//删除 name 为hm$collection->remove(array('name'=>'hm'));//断开MongoDB连接$m->close();?>[/php]