Example #1
0
// 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"));
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");
Example #2
0
     $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']])) {
             $t[$tag['api']] = array();