In this example, we are going to build the home page of our blog site, which will show the title and the content excerpt of every article stored in the database. Clicking on an article will take us to another page where we can see the full content of the article. Let's get to it:
1. Open up the text editor and create a new file named
blogs.php
. Put the following code in that file:<?php try { $connection = new Mongo(); $database = $connection->selectDB('myblogsite'); $collection = $database->selectCollection('articles'); } catch(MongoConnectionException $e) { die("Failed to connect to database ".$e->getMessage()); } $cursor = $collection->find(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset...