Skip to content

Instantly share code, notes, and snippets.

@hussani
Created July 24, 2013 22:13
Show Gist options
  • Save hussani/6075102 to your computer and use it in GitHub Desktop.
Save hussani/6075102 to your computer and use it in GitHub Desktop.
Simple Blog system with Respect Relational
<?php
use Respect\Relational\Mapper;
use Respect\Relational\Sql;
// Create instance of Mapper
$mapper = new Mapper(new PDO('mysql:host=127.0.0.1;port=3306;dbname=blog','root','root'));
// Persisting data
$newPost = new stdClass;
$newPost->title = "Test Post #2";
$newPost->content = "My content";
$newPost->author = 1;
$newPost->date = date('Y-m-d H:i:s');
$mapper->post->persist($newPost);
$mapper->flush();
// Get all posts
$mapper->post->fetchAll();
// Get posts by date
$posts = $mapper->post(array('date' => "2013-02-11 11:14:18"))->fetchAll();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment