Пример #1
0
foreach ($tables as $name => $fields) {
    $db->rawQuery("DROP TABLE " . $prefix . $name);
    createTable($prefix . $name, $fields);
}
if (!$db->ping()) {
    echo "db is not up";
    exit;
}
// insert test with autoincrement
foreach ($data as $name => $datas) {
    foreach ($datas as $d) {
        $id = $db->insert($name, $d);
        if ($id) {
            $d['id'] = $id;
        } else {
            echo "failed to insert: " . $db->getLastQuery() . "\n" . $db->getLastError();
            exit;
        }
    }
}
// bad insert test
$badUser = array('login' => null, 'customerId' => 10, 'firstName' => 'John', 'lastName' => 'Doe', 'password' => 'test', 'createdAt' => $db->now(), 'updatedAt' => $db->now(), 'expires' => $db->now('+1Y'), 'loginCount' => $db->inc());
$id = $db->insert("users", $badUser);
if ($id) {
    echo "bad insert test failed";
    exit;
}
// insert without autoincrement
$q = "create table {$prefix}test (id int(10), name varchar(10));";
$db->rawQuery($q);
$id = $db->insert("test", array("id" => 1, "name" => "testname"));