Hi, on this page you will find some example of use my database.
$result = Lazer::table('users')->findAll();
foreach($result as $row)
{
print_r($row);
}Lazer::table('users')->limit(5)->findAll(); /* Get five records */
Lazer::table('users')->limit(10, 5)->findAll(); /* Get five records from 10th */Lazer::table('users')->orderBy('id')->findAll();
Lazer::table('users')->orderBy('id', 'DESC')->findAll();
Lazer::table('users')->orderBy('id')->orderBy('name')->findAll();Lazer::table('users')->where('id', '=', 1)->findAll();
Lazer::table('users')->where('id', '>', 4)->findAll();
Lazer::table('users')->where('id', 'IN', array(1, 3, 6, 7))->findAll();
Lazer::table('users')->where('id', '>=', 2)->andWhere('id', '<=', 7)->findAll();
Lazer::table('users')->where('id', '=', 1)->orWhere('id', '=', 3)->findAll();Lazer::table('news')->groupBy('category_id')->findAll();Lazer::table('users')->count(); /* Number of rows */
Lazer::table('users')->findAll()->count(); /* Number of rows */
$users = Lazer::table('users')->findAll();
count($users); /* Number of rows */You can use it with rest of methods
Lazer::table('news')->where('id', '=', 2)->count();
Lazer::table('news')->groupBy('category_id')->count();Use when you want to get array with results, not an object to iterate.
Lazer::table('users')->findAll()->asArray();
Lazer::table('users')->findAll()->asArray('id'); /* key of row will be an ID */
Lazer::table('users')->findAll()->asArray(null, 'id'); /* value of row will be an ID */
Lazer::table('users')->findAll()->asArray('id', 'name'); /* key of row will be an ID and value will be a name of user */Caution! First letter of relationed table name is always uppercase.
For example you can get News with it Comments.
$news = Lazer::table('news')->with('comments')->findAll();
foreach($news as $post)
{
print_r($post);
$comments = $post->Comments->findAll();
foreach($comments as $comment)
{
print_r($comment);
}
}Also you can get News with it Author, Comments and each comment with it author
$news = Lazer::table('news')->with('users')->with('comments')->with('comments:users')->findAll();
foreach($news as $post)
{
print_r($post->Users->name); /* news author name */
$comments = $post->Comments->findAll(); /* news comments */
foreach($comments as $comment)
{
print_r($comment->Users->name); /* comment author name */
}
}In queries you can use all of features, simple example
$post->Comments->orderBy('author_id')->limit(5)->findAll(); /* news comments */Of course all of these examples can be used together
Lazer::table('users')->with('comments')->where('id', '!=', 1)->orderBy('name')->limit(15)->findAll()->asArray();