1,查看官方介绍http://www.mongodb.org/display/DOCS/PHP+Language+Center
- $db = new MongoClient( "mongodb://example.com:65432" );//连接
- $db = $m->test; //选择一个数据库
- $table = $db->t; //选择一个集合(表)
- $table->insert(array("title"=>"1111", "author"=>"lyj"));//插入记录
- $table->ensureIndex( array( "i" => 1 ) );//为t表i字段加入正序(升序)索引
- $one = $table->findOne();// 查询一条记录
- $cursor = $table->find(array('i'=>array('$lte'=>5)));//i<=5
- foreach($cursor as $vo){//循环输出
- foreach($vo as $k=>$v){
- echo $k.':'.$v.', ';
- }
- echo '<Br>';
- }
- $table->count(); //记录数