<?php $m = new Mongo(); //ÕâÀï²ÉÓÃĬÈÏÁ¬½Ó±¾»úµÄ27017¶Ë¿Ú£¬µ±È»ÄãÒ²¿ÉÒÔÁ¬½ÓÔ¶³ÌÖ÷»úÈç 192.168.0.4:27017,Èç¹û¶Ë¿ÚÊÇ27017£¬¶Ë¿Ú¿ÉÒÔÊ¡ÂÔ $db = $m -> comedy; // Ñ¡ÔñcomedyÊý¾Ý¿â£¬Èç¹ûÒÔǰû¸ÃÊý¾Ý¿â»á×Ô¶¯´´½¨£¬Ò²¿ÉÒÔÓÃ$m->selectDB("comedy"); $collection = $db->collection; //Ñ¡ÔñcomedyÀïÃæµÄcollection¼¯ºÏ£¬Ï൱ÓÚRDBMSÀïÃæµÄ±í£¬Ò²-¿ÉÒÔʹÓà $db->selectCollection("collection"); /*********Ìí¼ÓÒ»¸öÔªËØ**************/ $obj = array( "title" => "Calvin and Hobbes", "author" => "Bill Watterson" ); $collection->insert($obj); //½«$obj Ìí¼Óµ½$collection ¼¯ºÏÖÐ /*********Ìí¼ÓÁíÒ»¸öÔªËØ**************/ $obj = array( "title" => "XKCD", "online" => true ); $collection->insert($obj); $cursor = $collection->find(); foreach ($cursor as $obj) { //±éÀúËùÓм¯ºÏÖеÄÎĵµ echo $obj["title"] . "\n"; } $m->close(); //¶Ï¿ªMongoDBÁ¬½Ó ÏÂÃæÔÚ½éÉÜһЩ³£Óõĺ¯Êý£º $query = array( "i" => 71 ); $cursor = $collection->find( $query ); //ÔÚ$collectio¼¯ºÏÖвéÕÒÂú×ã$queryµÄÎĵµ while( $cursor->hasNext() ) { var_dump( $cursor->getNext() ); } $collection -> findOne(); //·µ»Ø$collection¼¯ºÏÖеÚÒ»¸öÎĵµ $collection -> count(); //·µ»Ø$collection¼¯ºÏÖÐÎĵµµÄÊýÁ¿ $coll->ensureIndex( array( "i" => 1 ) ); // Ϊi ¡°ÕâÒ»ÁС±¼ÓË÷Òý ½µÐòÅÅÁÐ $coll->ensureIndex( array( "i" => -1, "j" => 1 ) ); // Ϊi ¡°ÕâÒ»ÁС±¼ÓË÷Òý ½µÐòÅÅÁÐ jÉýÐò²éѯʱ£¬Ã¿¸öObject²åÈëʱ¶¼»á×Ô¶¯Éú³ÉÒ»¸ö¶ÀÌصÄ_id,ËüÏ൱ÓÚRDBMSÖеÄÖ÷¼ü£¬ÓÃÓÚ²éѯʱ·Ç³£·½±ã
È磺
¼ÙÈçÎÒÃÇÏëÐÞ¸ÄÏÂÃæÎĵµÖÐcommentsÖÐauthorµÄÃû×Ö<?php
$person = array("name" => "joe");
$people->insert($person);
$joe = $people->findOne(array("_id" => $person['_id']));
?>
¸üÐÂʱ£º
{
"_id" : ObjectId("4b06c282edb87a281e09dad9"),
"content" : "this is a blog post.",
"comments" :
[
{
"author" : "Mike",
"comment" : "I think that blah blah blah...",
},
{
"author" : "John",
"comment" : "I disagree."
}
]
}
ΪÁ˸ıäÄÚ²¿µÄÒ»¸öÓò, ÎÒÃÇÓà $set (±£Ö¤ÎĵµÖÐÆäËûÓò²»±»ÒƳý)²¢ÇÒcommentµÄË÷ÒýÒ²±ä»¯
<?php
$collection->update($criteria, array('$set' => array("comments.1" => array("author" => "Jim")))); //$criteria ΪҪ¸üеÄÔªËØ
?>
ɾ³ýÒ»¸öÊý¾Ý¿â
$m -> dropDB("comedy");
ÁгöËùÓпÉÓÃÊý¾Ý¿â
$m->listDBs(); //ÎÞ·µ»ØÖµ
ºÃÁ˾ÍÏÈ Ð´Õâô¶àÁË£¬ÓÐÐËȤµÄ»°¿ÉÒÔÔÚÍøÉÏËѵ½ÆäËûµÄ¹ØÓÚMongo-php APIµÄÓ÷¨£¡
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ