Esempio n. 1
0
{
    /**
     * primary
     * length 11
     * @var int
     */
    public $id;
    /**
     * data char
     * length 100
     * @var string
     */
    public $name;
}
$database = new \db\database('db_samples', new \db\link('default', $config->database, $config->username, $config->password));
$database->link('default')->debug = true;
$database->add('user');
$database->update();
//create lazarus
$lazarus = new \user();
$lazarus->name = 'Lazarus';
//save lazarus
$database->user->save($lazarus);
//kill lazarus
unset($lazarus);
//resurrect lazarus
$lazarus = $database->user->load(1);
\db\debug($lazarus);
//1 stands for lazarus id
//as soon as it is the first row in user table
//it will have id 1 auto generated
Esempio n. 2
0
//in this sample we will learn how to modify field settings
//it is done by documenting class and class properties
//it is improtant that documentation section starts with line /** and ends with line */
include './000.config.php';
include '../db.php';
class user
{
    /**
     * primary
     * length 11
     * @var int
     */
    public $id;
    /**
     * data char
     * length 100
     * @var string
     */
    public $name;
}
$database = new \db\database();
$database->link(new \db\link('default', $config->database, $config->username, $config->password));
$database->link('default')->debug = true;
$database->default = 'db_samples';
$database->add('user');
//so if you are coming here from previous example
//where user.name had not any configs you must have field 'name' in 'user' table char(128)
//** and after runing update field 'name' will become char(100) because you specified it in length comment in public $name documentation
$database->update();
\db\debug($database->user);
Esempio n. 3
0
<?php

include '../db.php';
include './013.model.php';
$database = new \db\database($config->hostname, $config->database, $config->username, $config->password);
$database->scan('.galaxy');
//truncate previous load table records
foreach ($database->context->tables as &$table) {
    $database->link($table->link)->query("truncate " . $table->name());
}
$alpha = $database->save(new \galaxy\star('alpha', 4));
$sun = $database->save(new \galaxy\star('sun', 1));
$database->save(new \galaxy\planet($alpha, 'xxx', 2, false, 100));
$database->save(new \galaxy\planet($alpha, 'xxx', 2, false, 123));
Esempio n. 4
0
<?php

include '../db.php';
$database = new \db\database('mysql:host=127.0.0.1', 'test', 'root', '1234');
$database->debug();
$result = $database->link()->query('show databases');
echo "<pre>";
if ($result) {
    foreach ($result as $row) {
        var_export($row);
    }
}
echo "</pre>";