About Us
Team
Values
Support
Open Source: dbentity
Overview
Download
Presentations and Articles
Examples: DBEntity Calling
Examples: DBEntity Classes
Examples: DBEntity Syntax
Examples: DB
Examples: DBQUERY
Examples: RBA
FAQ
Contact
ABOUT US
DBEntity - Calling Examples
// create a few 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 store the category_id.
list ($category_id) = mg('categories')->create_ex('name', 'tools');

// get the category, as an object.
$category = mg('categories')->get($category_id);

// create two products.
list ($product_id) = mg('products')->create_ex('name' , 'widget a', 'category', $category_id);
list ($product_id2) = mg('products')->create_ex('name' , 'widget b', 'category', $category_id);

// get the name of a product.
$name = mg('products')->get_name($product_id);

// get the product
$product = mg('products')->get_product($product_id);

// get all of the products for this category.
$products = mg('products')->get_by_category($category_id);