1. Go to this page and download the library: Download rogerthomas84/ohdm library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rogerthomas84 / ohdm example snippets
Config::init(
new \MongoClient(
'mongodb://127.0.0.1',
array('connect' => false)
),
'pets' // The database name
);
namespace My\Namespace\Name;
use OhDM\Collection;
class Cats extends Collection
{
public $name = null;
public function setName($name)
{
$this->name = $name;
}
public function getName()
{
return $this->name;
}
}
$record = new Cats();
$record->setName('fuzzy');
$record->save();
$record = Cats::findById(
new \MongoId('53466f2978f7a8bc5c1ae933')
);
if ($record) {
// $record is instance of Cats
echo 'My cats name is: ' . $record->getName();
} else {
// couldn't find it!
}