|
Project Information
Members
|
PHP STORMSimple ORM library for PHP 5 and higher. Base on PDO. NavigationDownload | How to install | Tutorials | API Features
Code example #1<?php
// take first five articles and order it by date
foreach(MArticle::many()->take(5)->orderBy(array("`date`" => "ASC")) as $article)
{
echo $article->head;
echo $article->author->login; // simple access to article author
// list page no.3 (10 items on page)
foreach($article->comments->page(3,10) as $comment)
{
....
}
?>This code executes 3 queries simmilar with these "SELECT * FROM `articles` ORDER BY `date` ASC LIMIT 5";
"SELECT * FROM `authors` WHERE id IN (1,2,3,4,5)";
"SELECT * FROM `comments` LIMIT 20,10 WHERE id IN (1,2,3,4,5)";Code example 2<?php
// simple create joins and agregations by STORM notation
MArticle::many()->where("comments->count() > 5 AND author->age > 16")->take(5)->orderBy(array("`date`" => "ASC")) as $article)
?> This code executes 1 query simmilar with this "SELECT * FROM `articles` JOIN `author` ON asdasd=asdasd WHERE (SELECT count(*) FROM `comments` JOIN `article` ON asdasd=asdasd) > 5 AND `authors`.age > 16 LIMIT 5 ORDER BY `date` => "ASC" Code example #3<?php
// simple create joins and agregations by STORM notation
$object = new MArticle();
$object->name;
$object->comments[] = new MComment(array("nick" => "", "text" => "asdasd"));
$object->author = MAuthor::one(array("login" => "petr23"));
$object->write();
?> This code executes 1 query simmilar with this "SELECT * FROM `articles` JOIN `author` ON asdasd=asdasd WHERE (SELECT count(*) FROM `comments` JOIN `article` ON asdasd=asdasd) > 5 AND `authors`.age > 16 LIMIT 5 ORDER BY `date` => "ASC"
|