???????и???????????php????mongoDb??????????????mongoDb??????????£??????????......
????1.????MongoDB?????

 

$conn = new Mongo();
??????????
//$conn=new Mongo(); #??????????????????.
//$conn=new Mongo(“172.21.15.69″); #???????????
//$conn=new Mongo(“xiaocai.loc:10086″); #?????????????????
//$conn=new Mongo(“xiaocai.loc”??array(“replicaSet”=>true)); #???????
//$conn=new Mongo(“xiaocai.loc”??array(“persist”=>”t”)); #???????
//$conn=new Mongo(“mongodb://sa:123@localhost”); #???????????
//$conn=new Mongo(“mongodb://localhost:27017??localhost:27018″); #????????????
//$conn=new Mongo(“mongodb:///tmp/mongo-27017.sock”); #???????
//$conn=new Mongo(“mongodb://admin_miss:miss@localhost:27017/test”??array(‘persist’=>’p'??”replicaSet”=>true)); #????

????2.???????????
????$db=$conn->mydb; #???mydb?????
????$collection=$db->myTable; #?????(???’??’)
????//$collection=$db->selectCollection(myTable); #?????д??
????//$collection=$conn->mydb->myTable; #??????д??
????3.??????????

 

$array=array(‘column_name’=>’col’.rand(100??999)??’column_exp’=>’xiaocai’);
$result=$collection->insert($array); #??????
echo “????ID:”.$array['_id']; #MongoDB?????????????
var_dump($result); #????:bool(true)
//**?????а????????????????????(????). **/
$array=array(‘column_name’=>’col’.rand(100??999)??’column_exp’=>’xiaocai2′);
$result=$collection->insert($array??true); #??????MongoDB???????????????????.(???д??????????????ò???????????)
echo “????ID:”.$array['_id']; #MongoDB?????????????
var_dump($result); #????:array(3) { ["err"]=> NULL ["n"]=> int(0) ["ok"]=> float(1) }

????4.??????????

 

//** ?????? ??????? **/
$where=array(‘column_name’=>’col123′);
$newdata=array(‘column_exp’=>’GGGGGGG’??'column_fid’=>444);
$result=$collection->update($where??array(‘$set’=>$newdata)); #$set:???????????????????????$pull $pullAll $pop $inc???????????????÷?
/*
* ???:
* ?????
* {“_id”:ObjectId(“4d635ba2d549a02801000003″)??”column_name”:”col123″??”column_exp”:”xiaocai”}
* ???滻????
* {“_id”:ObjectId(“4d635ba2d549a02801000003″)??”column_name”:”col123″??”column_exp”:”GGGGGGG”??”column_fid”:444}
*/
//** ?滻???? ??????????**/
$where=array(‘column_name’=>’col709′);
$newdata=array(‘column_exp’=>’HHHHHHHHH’??'column_fid’=>123);
$result=$collection->update($where??$newdata);
/*
* ???:
* ?????
* {“_id”:ObjectId(“4d635ba2d549a02801000003″)??”column_name”:”col709″??”column_exp”:”xiaocai”}
* ???滻????
* {“_id”:ObjectId(“4d635ba2d549a02801000003″)??”column_exp”:”HHHHHHHHH”??”column_fid”:123}
*/
//** ???????? **/
$where=array(‘column_name’=>’col’);
$newdata=array(‘column_exp’=>’multiple’??’91u’=>684435);
$result=$collection->update($where??array(‘$set’=>$newdata)??array(‘multiple’=>true));
/**
* ????’column_name’='col’???????
*/
//** ?????? **/
$where=array(’91u’=>684435);
$newdata=array(‘column_exp’=>’edit’);
$result=$collection->update($where??array(‘$set’=>$newdata??’$inc’=>array(’91u’=>-5)));
/**
* ????91u=684435???????????91u???5
*/