<?php
/* project: Database layer, file: db.php */
use pclib\orm\Selection;
//Include pclib framework
require 'pclib/pclib.php';
//Create pclib application
$app = new PCApp('demo');
$datasource = 'pdo_mysql://user:password@localhost/test';
//Connect to database and register it as $app->db
$app->db = new PCDb($datasource);
print "<h2>Using pclib ORM</h2>";
print "(Basic usage of classes Selection and Model - see source)<br><br>";
$sel = new Selection;
$sel->from('it_people')->where('money>1000');
println("Number of people with salary>1000: ", $sel->count() );
foreach ($sel as $person) {
println($person->id.". ", $person->name);
}
$richest = $sel->order('money desc')->first();
println("A richest man: ", $richest );
function println($label, $value)
{
print "<p><b>$label</b><span class='print-value'>$value</span></p>";
}
?>
Elapsed time: 1.21 ms