downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Data Types> <Runtime Configuration
Last updated: Wed, 25 Nov 2009

view this page in

Examples

This example shows how to connect, insert objects, query for objects, iterate through query results, and disconnect from a Mongo database.

Example #1 Mongo Example

<?php

include "mongo.php";

// connect
$m = new Mongo();

// select a database
$db $m->selectDB("comedy");
$collection $db->selectCollection("cartoons");

// add an element
$obj = array( "title" => "Calvin and Hobbes""author" => "Bill Watterson" );
$collection->insert($obj);

// add another element, with a different "shape"
$obj = array( "title" => "XKCD""online" => true );
$collection->insert($obj);

// find everything in the collection
$cursor $collection->find();

// iterate through the results
foreach ($cursor as $obj) {
    echo 
$obj["title"] . "\n";
}

// disconnect
$m->close();

?>

The above example will output something similar to:

Calvin and Hobbes
XKCD


add a note add a note User Contributed Notes
Examples
There are no user contributed notes for this page.

Data Types> <Runtime Configuration
Last updated: Wed, 25 Nov 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites