Created
July 24, 2013 22:13
-
-
Save hussani/6075102 to your computer and use it in GitHub Desktop.
Simple Blog system with Respect Relational
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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