Example #1
0
#!/usr/bin/env php
<?php 
require_once dirname(__FILE__) . '/Link.php';
require_once dirname(__FILE__) . '/LinkPeer.php';
define('DB_NAME', 'links');
$m = new Mongo();
$linkPeer = new LinkPeer($m->selectDb(DB_NAME));
// Ensure the db is empty
foreach ($linkPeer->fetchAll() as $link) {
    $linkPeer->delete($link);
}
// Print the contens of the database
echo "> initial database values:\n";
foreach ($linkPeer->fetchByTag('com') as $link) {
    echo "{$link}\n";
}
echo "\n----\n";
// Add some links
$lnk1 = new Link();
$lnk1->setUrl('http://www.google.com');
$lnk1->addTag('google');
$lnk1->addTag('com');
$lnk2 = new Link();
$lnk2->setUrl('http://www.mongodb.org');
$lnk2->addTag('mongodb');
$lnk2->addTag('org');
$lnk3 = new Link();
$lnk3->setUrl('http://www.ibuildings.com');
$lnk3->addTag('ibuildings');
$lnk3->addTag('com');
$lnk4 = new Link();