// echo_r just prints out in a structured format... (defined in the framework)
// create some tables.
$qs = array('drop table if exists categories'
, 'create table categories (id int primary key auto_increment, name varchar(32))'
, 'drop table if exists products'
, 'create table products (id int primary key auto_increment, category_id int, name varchar(32))'
);
foreach ($qs as $q) { db::q($q);}
// create a category and a product.
list ($category_id) = mg('categories')->create_ex('name', 'tools');
list ($product_id) = mg('products')->create_ex('name' , 'widget a', 'category', $category_id);
// create a dbquery object
$q = new dbquery(array('select' => 'p.id, p.name'
, 'from' => 'products p'
, 'ijoin' => array('c' => array('table' => 'categories', 'on' => 'c.id = p.category_id'))
, 'order_by' => 'p.name'
));
echo_r($q);
// export the dbquery to a string...
echo_r($q->to_sql());
// export the dbquery to a string, then convert to actual objects.
echo_r(db::objects($q->to_sql()));
// add a where clause
$q->add_where('c.id = 1');
// now execute this one...
echo_r($q->to_sql());
echo_r(db::objects($q->to_sql()));




