本文整理汇总了PHP中SQLite3::createFunction方法的典型用法代码示例。如果您正苦于以下问题:PHP SQLite3::createFunction方法的具体用法?PHP SQLite3::createFunction怎么用?PHP SQLite3::createFunction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQLite3
的用法示例。
在下文中一共展示了SQLite3::createFunction方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: locationKeywordSearch
/**
* 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: mainAction
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: __construct
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: fetch_relevant_pois
/**
* @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: sendSMS
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: parse
<?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: recorded
}
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);