DB.PHP - PHP ORM

Query helper functions

Before using queries whe need to now about few helper functions:

namespace shop
{
    class product
    {
        public $id;
        public $name;
    }
}
$database->add ('shop.product');
$database->update ();

In this case table with name 'shop_product' will be created with fields 'id' and 'name'. Full table name for class looks like my_db.shop_product and full field name for property 'name' looks like my_db.shop_product.name.

In custum queries you will need to use full table and field names to avoid ambigous field name errors.

\db\table::name

To get table name use:

$database->shop->product->table();
//Outputs something like `my_db`.`shop_product`

Or:

$database->shop->product->name();
//Outputs something like `my_db`.`shop_product`
\db\table::field

To get field name use:

$database->shop->product->field('name');
//Outputs something like `my_db`.`shop_product`.`name`

The name parameter for 'field' function must be property name, this means if you have public $login than property name is 'login' and to get full field name for login use $database->path->to->table->field('login')

\db\table::value

value function gerenates something useful also:

$database->shop->product->value('name','Milk');
//`my_db`.`shop_product`.`name`='Milk'
\db\string

To escape string use function \db\string. Anything that does not go through the db.php functions like custom strings and comes from user input and used in queries must be escaped.

$database->shop->product->field('cost').">".\db\string($_REQUEST['cost']);
//`my_db`.`shop_product`.`name`>5.1