blog;
$collection = $db->post;
//add a record
$document = array(
"title" => "Beginning Android Programming",
"content" => "A hands-on introduction to the latest release of the Android OS");
$collection->insert($document);
//add another record
$document = array(
"title" => "Beginning Java Programming: The Object Oriented Approach",
"content" => "A comprehensive resource for getting started with the ever-popular Java programming language");
$collection->insert($document);
// add a record
$document = array(
"title" => "Professional iOS Programming",
"content" => "Hands-on guidance for programming the next generation of iOS apps");
$collection->insert($document);
// find everything in the collection
$cursor = $collection->find();
// iterate through the results
echo "After the insert of 3 records"."
";
foreach ($cursor as $document) {
echo "
- Title: ".$document["title"] . " / "."Content: ". $document["content"]."
";
}
echo "After the addition of author"."
";
$newdata = array('$set' => array("author" => "Wei-Meng Lee"));
$collection->update(array("title" => "Beginning Android Programming"), $newdata);
$newdata = array('$set' => array("author" => "Deepak Vohra"));
$collection->update(array("title" => "Beginning Java Programming: The Object Oriented Approach"), $newdata);
$newdata = array('$set' => array("author" => "Peter van de Put"));
$collection->update(array("title" => "Professional iOS Programming"), $newdata);
$cursor = $collection->find();
// iterate through the results
foreach ($cursor as $document) {
echo "- Title: ".$document["title"] . " / "."Author: ".$document["author"] . " / "."Content: ". $document["content"]."
";
}
echo "Print out just the first record"."
";
$cursor = $collection->find(array("author" => "Wei-Meng Lee"));
foreach ($cursor as $document) {
echo "- Title: ".$document["title"] . " / "."Author: ".$document["author"] . " / "."Content: ". $document["content"]."
";
//Test print of array
//print_r($document);
}
$cursor = $collection->remove();
?>