예제 #1
0
    $q .= ")";
    $db->rawQuery($q);
}
// rawQuery test
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;
}
    global $db;
    //$q = "CREATE TABLE $name (id INT(9) UNSIGNED PRIMARY KEY NOT NULL";
    $q = "CREATE TABLE {$name} (id INT(9) UNSIGNED PRIMARY KEY AUTO_INCREMENT";
    foreach ($data as $k => $v) {
        $q .= ", {$k} {$v}";
    }
    $q .= ")";
    $db->rawQuery($q);
}
foreach ($tables as $name => $fields) {
    $db->rawQuery("DROP TABLE " . $prefix . $name);
    createTable($prefix . $name, $fields);
}
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();
        }
    }
}
$db->orderBy("id", "asc");
$users = $db->get("users");
if ($db->count != 3) {
    echo "Invalid total insert count";
    exit;
}
$db->where("active", true);
$users = $db->get("users");