コード例 #1
0
/**
 * Get a list of venues which are whitin $distance of location ($lat, long)
 * and have a category similar to $keyword
 * 
 * returns list of venue information
 */
function locationKeywordSearch($lat, $long, $keyword, $distance, $limit = 25)
{
    $_SESSION['lat'] = $lat;
    $_SESSION['long'] = $long;
    $_SESSION['keyword'] = $keyword;
    global $databaseName;
    $db = new SQLite3($databaseName);
    // Attach methods haversineGreatCircleDistance,stringSimilarity to
    // Database engine so that we can use them in our query
    $db->createFunction("DISTANCE", "haversineGreatCircleDistance");
    $db->createFunction("SIMILARITY", "stringSimilarity");
    // Search query: get venue information for venues close to location, with categories most similar to the keyword/phrase
    $statement = $db->prepare('SELECT venueId, name, lat, long, categories, address, DISTANCE(lat, long) as distance, SIMILARITY(categories)' . " as similarity FROM Venues WHERE distance < :dist ORDER BY similarity DESC LIMIT :limit");
    // Bind some parameters to the query
    $statement->bindValue(':limit', $limit);
    $statement->bindValue(':dist', $distance, SQLITE3_INTEGER);
    // Obtain the venues from the db and put them in a list
    $qry = $statement->execute();
    $venues = [];
    while ($venue = $qry->fetchArray()) {
        $venues[] = $venue;
    }
    $db->close();
    return $venues;
}
コード例 #2
0
ファイル: DbTask.php プロジェクト: siciarek/suggester
 public function mainAction()
 {
     $this->dbconf = Phalcon\DI::getDefault()->getConfig()->database;
     $file = $this->getDI()->getConfig()->dirs->config . DIRECTORY_SEPARATOR . 'schema' . DIRECTORY_SEPARATOR . $this->dbconf->adapter . '.sql';
     $this->schema = realpath($file);
     if ($this->schema === false) {
         throw new \Exception('Unsupported database adapter: ' . $this->dbconf->adapter);
     }
     echo "{$this->dbconf->adapter}\n";
     echo $this->dropDatabase();
     switch ($this->dbconf->adapter) {
         case 'mysql':
             echo $this->createDatabase();
             echo $this->loadSchema();
             echo $this->loadFixtures();
             break;
         case 'sqlite':
             $dbfile = $this->di->getConfig()->dirs->data . DIRECTORY_SEPARATOR . $this->di->get('config')->database->dbname . '.sqlite';
             $db = new SQLite3($dbfile);
             chmod($dbfile, 0664);
             $db->createFunction('MD5', 'md5');
             $db->exec(file_get_contents($this->schema));
             $db->exec(file_get_contents(preg_replace('/sqlite.sql$/', 'fixtures.sql', $this->schema)));
             break;
         default:
             throw new \Exception('Unsupported database adapter: ' . $this->dbconf->adapter);
             break;
     }
 }
コード例 #3
0
ファイル: Connection.php プロジェクト: jsor/dbal-sqlite3
 public function __construct($filename, $flags = null, $encryptionKey = null, $busyTimeout = null, array $userDefinedFunctions = array(), array $userDefinedExtensions = array())
 {
     if (null === $flags) {
         $flags = \SQLITE3_OPEN_READWRITE | \SQLITE3_OPEN_CREATE;
     }
     $this->_conn = new SQLite3($filename, $flags, $encryptionKey);
     if (null !== $busyTimeout) {
         $this->_conn->busyTimeout($busyTimeout);
     } else {
         $this->_conn->busyTimeout(60000);
     }
     foreach ($userDefinedFunctions as $fn => $data) {
         $this->_conn->createFunction($fn, $data['callback'], $data['numArgs']);
     }
     foreach ($userDefinedExtensions as $extension) {
         $this->_conn->loadExtension($extension);
     }
 }
コード例 #4
0
/**
 * @param $lat latitude of the client's location
 * @param $lon longitude of the client's location
 * @param $dbname name of the database
 * @param $lang Detected language for localization
 * @return string An XML string containing POIs close to the client's location
 */
function fetch_relevant_pois($lat, $lon, $dbname)
{
    if (is_null($lat) || is_null($lon)) {
        // Return empty result.
        createLocationBasedAREL(array());
        return null;
    }
    //connect to the SQLite database
    $db = new SQLite3($dbname);
    $db->createFunction('DISTANCE', 'sqlite3_distance_func', 4);
    //run a proximity query to fetch ONLY close by POIs
    $records = $db->query("SELECT * FROM POIsM WHERE DISTANCE(latitude,longitude,{$lat},{$lon}) < 50 ORDER BY abs(latitude - {$lat}) + abs(longitude - {$lon});");
    //build an AREL XML with the relevant POIs
    $poiXML = build_xml($records, "en");
    $db->close();
    return $poiXML;
}
コード例 #5
0
ファイル: conf.php プロジェクト: HuiZone/Waruga
                if (is_dir($dirPath . $folder)) {
                    deleteDir($dirPath . $folder . "/");
                } else {
                    unlink($dirPath . $folder);
                }
            }
        }
        rmdir($dirPath);
        closedir($temp);
    }
}
function sendSMS($nomorhp, $sms)
{
    global $config;
    $status = file_get_contents($config->SMS_URL_Parameter . "?" . $config->SMS_Number_Parameter . "={$nomorhp}&" . $config->SMS_Text_Parameter . "=" . urlencode($sms) . "&" . $config->SMS_Additional_Parameter);
    if (strpos($status, $config->SMS_Success_Parameter) === false) {
        return '<span class="label label-danger"><span class="glyphicon glyphicon-remove"></span>' . " GAGAL</span><br>\r\n";
    } else {
        return '<span class="label label-success"><span class="glyphicon glyphicon-ok"></span>' . " SUKSES</span><br>\r\n";
    }
}
$db->createFunction('labelExist', 'labelExist', 2);
function labelExist($label, $dicari)
{
    if (strpos($label, $dicari) === false) {
        return false;
    } else {
        return true;
    }
}
$bulanArray = array("Januari", "Pebruari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember");
コード例 #6
0
ファイル: all_txt.php プロジェクト: jatolmed/links
<?php

require "../includes/include.php";
$sections = [];
$count = 0;
$sqlite = new SQLite3($db_str, SQLITE3_OPEN_READONLY);
$sqlite->createFunction("parse", "parseRecord", 12);
$sqlite->exec("select parse(s_id,s_name,s_container,s_position,s_created,s_updated,l_id,l_url,l_comment,l_created,l_updated,l_accessed) from sections left join links on s_id=l_section order by s_id asc");
usort($sections, function ($a, $b) {
    return $a->getPosition() - $b->getPosition();
});
$all = "";
foreach ($sections as $section) {
    if ($section->getContainer() == null) {
        $all .= $section->sortSections()->sortLinks()->toString();
    }
}
$sqlite->close();
header('Content-Type: text/plain');
header("Content-Transfer-Encoding: Ascii");
header("Content-disposition: attachment; filename=\"links-" . date("Ymd-His") . ".txt\"");
print $all;
コード例 #7
0
ファイル: open_db.php プロジェクト: mslagmu/Atelier
    }
    if (!(strpos($followers, $login) === FALSE)) {
        return 1;
    }
    if (!(strpos($persons, $login) === FALSE)) {
        return 1;
    }
    return 0;
}
function recorded($login, $persons)
{
    if (!(strpos($persons, $login) === FALSE)) {
        return 1;
    }
    return 0;
}
function month($time)
{
    return utf8_encode(strftime('%B %Y', $time));
}
function week($time)
{
    $t2 = $time - $_SESSION["date_debut"];
    //timestamp du 2 octobre 2014
    return floor($t2 / 604800);
    //Correspond au nombre de seconde pour 7 jours
}
$db->createFunction('concerned', 'concerned', 4);
$db->createFunction('recorded', 'recorded', 2);
$db->createFunction('month', 'month', 1);
$db->createFunction('week', 'week', 1);