}
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");
if ($db->count != 1) {
    echo "Invalid total insert count with boolean";
    exit;
}
$db->where("active", false);
$db->update("users", array("active" => $db->not()));
if ($db->count != 2) {
    echo "Invalid update count with not()";
Пример #2
0
// 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"));
if (!$id) {
    echo "insert without autoincrement failed";
    exit;
}
$db->get("test");
if ($db->count != 1) {
    echo "insert without autoincrement failed -- wrong insert count";
    exit;
}
$q = "drop table {$prefix}test;";
$db->rawQuery($q);
$db->orderBy("`id`", "asc");
$users = $db->get("users");
if ($db->count != 3) {
    echo "Invalid total insert count";
    exit;
}
// insert with on duplicate key update
$user = array('login' => 'user3', 'active' => true, 'customerId' => 11, 'firstName' => 'Pete', 'lastName' => 'D', 'password' => $db->func('SHA1(?)', array("secretpassword2+salt")), 'createdAt' => $db->now(), 'updatedAt' => $db->now(), 'expires' => $db->now('+1Y'), 'loginCount' => $db->inc(3));
$updateColumns = array("updatedAt");
$insertLastId = "id";
sleep(1);
$db->onDuplicate($updateColumns, "id");
$db->insert("users", $user);
$nUser = $db->where('login', 'user3')->get('users');
if ($db->count != 1) {
    echo "onDuplicate update failed. ";
Пример #3
0
 } else {
     $rad = $app->request()->params('radius');
 }
 if ($app->request()->params('lat') == null) {
     $lat = 1;
 } else {
     $lat = $app->request()->params('lat');
 }
 if ($app->request()->params('lon') == null) {
     $lon = 1;
 } else {
     $lon = $app->request()->params('lon');
 }
 $cols = array("*", "( 6371 * acos( cos( radians(" . $lat . ") ) * cos( radians( lat ) ) * cos( radians( lon ) - radians(" . $lon . ") ) + sin( radians(" . $lat . ") ) * sin(radians(lat)) ) ) AS distance");
 $db->where("( 6371 * acos( cos( radians(" . $lat . ") ) * cos( radians( lat ) ) * cos( radians( lon ) - radians(" . $lon . ") ) + sin( radians(" . $lat . ") ) * sin(radians(lat)) ) )", $rad, "<");
 $db->orderBy("distance", "asc");
 $pictures = $db->get("picture", null, $cols);
 $_output = array();
 foreach ($pictures as $picture) {
     $tmp = array();
     //$tmp['url2'] = 'https://htv.utfapp.com/index/index.php/thumb?path='.base64_encode($picture['path']);
     $tmp['url'] = 'https://htv.utfapp.com/index/index.php/thumb2?path=/&id=' . $picture['idPicture'];
     $tmp['distance'] = $picture['distance'];
     $tmp['address'] = $picture['address'];
     $tmp['city'] = $picture['city'];
     $tmp['country'] = $picture['country'];
     $tmp['date'] = $picture['date'];
     $tags = $db->rawQuery("SELECT tag, api FROM gallery WHERE idPicture = " . $picture['idPicture'] . " ORDER BY probs DESC");
     $t = array();
     foreach ($tags as $tag) {
         if (!isset($t[$tag['api']])) {