本文整理汇总了PHP中SQLite3类的典型用法代码示例。如果您正苦于以下问题:PHP SQLite3类的具体用法?PHP SQLite3怎么用?PHP SQLite3使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SQLite3类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: get_db
function get_db()
{
global $authdb;
$db = new SQLite3($authdb, SQLITE3_OPEN_READWRITE);
$db->exec('PRAGMA foreign_keys = 1');
return $db;
}
开发者ID:RavenB,项目名称:nsedit,代码行数:7,代码来源:misc.inc.php
示例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;
}
}
开发者ID:siciarek,项目名称:suggester,代码行数:29,代码来源:DbTask.php
示例3: missing_files_from_directory
/**
* Checks which files of a directory are missing in a SQLite3 database and returns a list of them.
*
* @arg dir The directory for which to check
* @arg dbfile The file containing the database
* @arg table The table name of the database
* @arg col The column containing the filenames
* @arg enckey The encryption key used for the database
* @returns A list of files missing from the database, or an empty list
*/
function missing_files_from_directory($dir, $dbfile, $table, $col, $enckey = NULL)
{
$missing = array();
$dirscan = scandir($dir, SCANDIR_SORT_ASCENDING);
if ($dirscan == false) {
// Either $dir is not a directory or scandir had no success
return $missing;
}
try {
if (is_string($enckey)) {
$db = new SQLite3($dbfile, SQLITE3_OPEN_READONLY, $enckey);
} else {
$db = new SQLite3($dbfile, SQLITE3_OPEN_READONLY);
}
} catch (Exception $e) {
// Database could not be opened; return empty array
return $missing;
}
foreach ($dirscan as $file) {
if (is_dir($file) || is_link($file)) {
// Filtering out directories (. and ..) and links {
continue;
}
if ($db->querySingle("SELECT EXISTS(SELECT * FROM " . $table . " WHERE " . $col . " = '" . SQLite3::escapeString($file) . "');")) {
// if an entry exists, returns TRUE, otherwise FALSE; invalid or failing queries return FALSE
continue;
}
// entry does not exist; add to array
$missing[] = $file;
}
$db->close();
sort($missing, SORT_LOCALE_STRING | SORT_FLAG_CASE);
return $missing;
// sort based on the locale, case-insensitive
}
开发者ID:jankohoener,项目名称:sqlite-scripts,代码行数:45,代码来源:missingfiles.php
示例4: 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;
}
开发者ID:wardlawp,项目名称:VenueWebsite,代码行数:31,代码来源:SearchMethods.php
示例5: check_links
function check_links()
{
//Before checking anything, check if laurentian.concat.ca is resolving.
$catalogue_link = fopen("http://laurentian.concat.ca/", "r");
if (!$catalogue_link) {
die("There may be a problem with laurentian.concat.ca so this process is going to halt. If this persists, contact Kevin Beswick");
}
fclose($catalogue_link);
//Check all links from database, if active, leave alone, if not active, delete them.
$db_session = new SQLite3('reserves.db');
$query = "SELECT bookbag_id from reserve";
$results = $db_session->query($query) or die($db_session->lastErrorMsg());
$begin_link = "http://laurentian.concat.ca/opac/extras/feed/bookbag/opac/";
$end_link = "?skin=lul";
$count = 0;
while ($row = $results->fetchArray()) {
$file = fopen($begin_link . $row["bookbag_id"] . $end_link, "r");
if (!$file) {
//remove from list
$query = "DELETE from reserve where bookbag_id = " . $row["bookbag_id"];
$db_session->exec($query) or die("not working... " . $db_session->lastErrorMsg());
$count++;
}
fclose($file);
}
echo "Done removing dead links... " . $count . " were removed.";
}
开发者ID:kbeswick,项目名称:library,代码行数:27,代码来源:admin.php
示例6: getCars
function getCars($query)
{
$db = new SQLite3('car.db');
$results = $db->query($query);
echo "<table class=\"search-results\">";
echo "<th>Reg nummer</th>";
echo "<th>Märke</th>";
echo "<th>Modell</th>";
echo "<th>Pris</th>";
echo "<th>Antal mil</th>";
echo "<th>Årsmodell</th>";
echo "<th>Redigera</th>";
$numRows = 0;
while ($row = $results->fetchArray()) {
$numRows++;
}
if ($numRows === 0) {
echo "<tr><td colspan=\"8\">Inga resultat för: \"" . $_POST['search'] . "\"</td></tr>";
} else {
while ($row = $results->fetchArray()) {
echo "<tr>\n <td class=\"car-regnr\"><a data-id=\"{$row['id']}\" href=\"#\" class=\"car-info\">{$row['regnr']}</td>\n <td class=\"car-brand\">{$row['brand']}</td>\n <td class=\"car-model\">{$row['model']}</td>\n <td class=\"car-price\">{$row['price']}</td>\n <td class=\"car-milage\">{$row['milage']}</td>\n <td class=\"car-year\">{$row['year']}</td>\n <td class=\"car-edit-link\"><a data-id=\"{$row['id']}\" href=\"#\" class=\"car-info\">Redigera</a></td>\n </tr>";
}
echo "</table>";
}
$db->close();
}
开发者ID:trullarn,项目名称:php,代码行数:26,代码来源:edit_car_php.php
示例7: anubisFILE
function anubisFILE($idmd5, $fileName)
{
#Execute the Python Script
#python /var/www/anubis/submit_to_anubis.py /var/www/mastiff/MD5/filename.VIR
$command = 'python /var/www/anubis/submit_to_anubis.py -u ' . $anubisUser . ' -p ' . $anubisPass . ' "/var/www/mastiff/' . $idmd5 . '/' . $fileName . '"';
$output = shell_exec($command);
$anubisRes['out'] = $output;
$pattern = '/https?\\:\\/\\/[^\\" ]+/i';
preg_match($pattern, $output, $matches);
#echo '<pre>';
# echo '$matches: ';
# var_dump($matches);
#echo '</pre>';
$anubisLink = $matches[0];
$anubisLink = strstr($anubisLink, "\n", true);
$anubisRes['link'] = $anubisLink;
#Update the Database
$db = new SQLite3('../mastiff/mastiff.db');
$result = $db->exec('UPDATE mastiff SET anubis = "' . $anubisLink . '" WHERE md5 = "' . $idmd5 . '"');
if (!$result) {
$anubisRes['db'] = $db->lastErrorMsg();
} else {
$anubisRes['db'] = $db->changes() . ' Record updated successfully.';
}
return $anubisRes;
}
开发者ID:bhargavz,项目名称:WIPSTER,代码行数:26,代码来源:anubis.php
示例8: ConvertDB
function ConvertDB($fname)
{
// echo "=> {$fname}\n";
if (!file_exists($fname)) {
exit(10);
}
$db = new SQLite3('base.sqlite');
$db->exec("pragma synchronous = off;");
$tablename = pathinfo($fname, PATHINFO_FILENAME);
$pdx = new Paradox();
$pdx->Open($fname);
$db->exec(createdb_schema($tablename, $pdx->GetSchema()));
$db->exec('DELETE FROM ' . $tablename);
if ($records = $pdx->GetNumRows()) {
$schema = $pdx->GetSchema();
// print_r($schema);
for ($rec = 0; $rec < $records; $rec++) {
$pdx->GetRow($rec);
// if ($rec > 2) break;
$query = 'INSERT INTO `' . $tablename . '` VALUES (';
$values = '';
foreach ($pdx->row as $fieldName => $value) {
switch ($schema[$fieldName]['type']) {
case 1:
$value = brackets(iconv('windows-1251', 'UTF-8', $value));
break;
case 2:
$value = brackets($pdx->GetStringfromDate($value));
break;
case 21:
$value = brackets($pdx->GetStringfromTimestamp($value));
break;
case 4:
$value = (int) $value;
break;
case 6:
$value = (double) $value;
break;
case 9:
$value = (int) $value;
break;
case 13:
$value = "X" . brackets(bin2hex($value));
break;
default:
$value;
break;
}
$values .= $value . ', ';
// print "{$schema[$fieldName]['type']}\t{$fieldName}\t{$value}\n";
}
$values = rtrim($values, ', ');
$query .= $values . ");\n";
// print trim($query).PHP_EOL;
$db->exec($query);
}
return true;
}
$pdx->Close();
}
开发者ID:qwexak,项目名称:parking-paradox,代码行数:60,代码来源:converter.php
示例9: insertData
/**
* @param StatsModel $model
* @param string $data
* @param int $count
* @return \SQLite3Result
*/
public function insertData(StatsModel $model, $data, $count = 1)
{
$statement = $this->conn->prepare(sprintf("INSERT INTO `%s` (`date`, `count`, `data`) VALUES (%d, :count, :data);", $model->getEvent(), intval(date('U'))));
$statement->bindValue(':data', $data, SQLITE3_TEXT);
$statement->bindValue(':count', $count, SQLITE3_INTEGER);
return $statement->execute();
}
开发者ID:jlaso,项目名称:simple-stats,代码行数:13,代码来源:DB.php
示例10: getDB
public static function getDB()
{
$con = new SQLite3('db/newsdb.db');
$con->exec('PRAGMA foreign_keys = ON;');
return $con;
#return new SQLite3('../sqlite/newsdb.db.new');
}
开发者ID:PisaCoderDojo,项目名称:dojo-wp-site,代码行数:7,代码来源:Helper.php
示例11: caching
function caching($comics_id, $zip_path, $image_ext)
{
$comic = zip_open($zip_path);
if (!is_resource($comic)) {
die("[ERR]ZIP_OPEN : " . $zip_path);
}
$inzip_path = "";
$count = 0;
$files = null;
$db = new SQLite3(DB);
$db->exec("BEGIN DEFERRED;");
while (($entry = zip_read($comic)) !== false) {
$inzip_path = zip_entry_name($entry);
$cache_name = md5($zip_path . "/" . $inzip_path) . '.' . get_ext($inzip_path);
// 画像か否か
if (!is_image($inzip_path, $image_ext)) {
continue;
}
$data = zip_entry_read($entry, zip_entry_filesize($entry));
$filepath = CACHE . '/' . $cache_name;
file_put_contents($filepath, $data);
$count++;
query("INSERT INTO images (comics_id, page, filepath) VALUES (" . $comics_id . ", " . $count . ", '" . $filepath . "')", $db);
}
zip_close($comic);
query("UPDATE comics SET pages = " . $count . " WHERE id = " . $comics_id, $db);
$db->exec("COMMIT;");
}
开发者ID:undisputed-seraphim,项目名称:manga_server,代码行数:28,代码来源:view.php
示例12: OpenLogFile
public function OpenLogFile()
{
$db = null;
$filename = $this->logdir . "/" . $this->logfile;
if (!file_exists($this->logdir)) {
mkdir($this->logdir, 0755, true);
}
$db = new SQLite3($filename);
$sql = <<<SQL
CREATE TABLE IF NOT EXISTS account_attempt (
time_attempted date not null default CURENT_TIMESTAMP,
username text not null default '',
email text not null default '',
ip text not null default '',
trigger text not null default '',
confidence float not null default 0.0,
accepted text default 'Y',
verified text default 'N',
primary key (time_attempted, username, email, ip)
)
SQL;
$db->exec($sql);
$sql = <<<IDXSQL
CREATE INDEX IF NOT EXISTS account_verification
ON account_attempt (accepted, verified)
IDXSQL;
$db->exec($sql);
return $db;
}
开发者ID:ClayDowling,项目名称:StopForumSpam,代码行数:29,代码来源:SpamLogger.php
示例13: handle_admin
function handle_admin()
{
if (empty($_POST['admin_account']) == false && empty($_POST['admin_password']) == false) {
$account = $_POST['admin_account'];
$password = md5($_POST['admin_password']);
//password: ccc95
$file_path = "../sqlite/books_web.s3db";
if (file_exists($file_path)) {
$link = new SQLite3($file_path);
$sql_cmd = "SELECT password FROM root_account WHERE password='{$password}'";
$result = $link->query($sql_cmd);
$i = 0;
$row = array();
while ($res = $result->fetchArray(SQLITE3_ASSOC)) {
$row[$i]['password'] = $res['password'];
$i++;
}
if (count($row) != 0) {
$_SESSION['root'] = "root";
return "admin login success.";
} else {
return "admin login failed.";
}
$link->close();
} else {
return "cannot link database.";
}
} else {
return "post error";
}
}
开发者ID:peter279k,项目名称:phpunit-test,代码行数:31,代码来源:handle_admin3.php
示例14: main
function main()
{
global $G;
message("PHP testing sandbox (%s) version %s", $G['ME'], VERSION);
try {
$db = new SQLite3(DATABASE);
$db->exec('DROP TABLE IF EXISTS t');
$db->exec('CREATE TABLE t (a, b, c)');
message('Table t sucessfully created');
$sth = $db->prepare('INSERT INTO t VALUES (?, ?, ?)');
$sth->bindValue(1, 'a');
$sth->bindValue(2, 'b');
$sth->bindValue(3, 'c');
$sth->execute();
$sth->bindValue(1, 1);
$sth->bindValue(2, 2);
$sth->bindValue(3, 3);
$sth->execute();
$sth->bindValue(1, 'one');
$sth->bindValue(2, 'two');
$sth->bindValue(3, 'three');
$sth->execute();
$sth = $db->prepare('SELECT * FROM t');
$result = $sth->execute();
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
message('%s, %s, %s', $row['a'], $row['b'], $row['c']);
}
} catch (Exception $e) {
message($e->getMessage());
}
}
开发者ID:kbglobal51,项目名称:yii-trackstar-sample,代码行数:31,代码来源:14_example-SQLite3.php
示例15: get_mbtiles_data
function get_mbtiles_data($file_path)
{
$db_mbtiles = new SQLite3($file_path);
// Min Zoom and Max Zoom
$zoom_range_query = "select min(zoom_level), max(zoom_level) from tiles";
$zoom_range_results = $db_mbtiles->query($zoom_range_query);
$zoom_range = $zoom_range_results->fetchArray();
$min_zoom = $zoom_range[0];
$max_zoom = $zoom_range[1];
// Get zoom, column, and row for each tile
$query = "select zoom_level, avg(tile_column), avg(tile_row) from tiles group by zoom_level";
$results = $db_mbtiles->query($query);
$rows = array();
while ($row = $results->fetchArray()) {
$rows[] = $row;
}
$center_tile = $rows[floor(0.5 * count($rows))];
$center_tile_zoom = $center_tile[0];
$center_tile_x = floor($center_tile[1]);
// Column
$center_tile_y = round(pow(2, $center_tile_zoom) - $center_tile[2] - 1);
// Converted Row
$mbtiles_data = array("min_zoom" => $min_zoom, "max_zoom" => $max_zoom, "center_coordinates" => array("zoom" => $center_tile_zoom, "x" => intval($center_tile_x), "y" => intval($center_tile_y)));
return $mbtiles_data;
}
开发者ID:ndpgroup,项目名称:fp-legacy,代码行数:25,代码来源:lib.mbtiles.php
示例16: cleanup_listeners_othermounts
function cleanup_listeners_othermounts($maxagelimitstamp_othermounts, $fingerprint, $mountpoint)
{
$db = new SQLite3('load.db');
$db->busyTimeout(100);
$db->exec("DELETE FROM t_listeners WHERE timestamp < {$maxagelimitstamp_othermounts} AND fingerprint = '{$fingerprint}' AND mountpoint != '{$mountpoint}'");
$db->close();
}
开发者ID:xxaxxelxx,项目名称:xx_loadbalancer,代码行数:7,代码来源:functions.php
示例17: getEvents
function getEvents()
{
global $db;
$token = trim(file_get_contents('config/token.txt'));
$mainPage = pullUrl("https://techspring.nationbuilder.com/api/v1/sites/v2/pages/events?starting=" . date("Y-m-d") . "&access_token=" . $token . "");
$obj = json_decode($mainPage);
//echo "<pre>" . json_encode($obj, JSON_PRETTY_PRINT) . "</pre>";
if ($db = new SQLite3('local_db.sql')) {
$q = @$db->query('CREATE TABLE IF NOT EXISTS events (eid INTEGER, start_time TEXT, end_time TEXT, name TEXT, description TEXT, PRIMARY KEY(eid))');
$q = @$db->query('CREATE TABLE IF NOT EXISTS rsvp (eid INTEGER, uid INTEGER)');
}
foreach ($obj->results as $eventObj) {
echo "<br/>{$eventObj->id} - {$eventObj->name} - {$eventObj->start_time} - {$eventObj->end_time} - {$eventObj->intro} <br />";
$startTime = strtotime($eventObj->start_time);
$endTime = strtotime($eventObj->end_time);
echo "Date: " . date("l, F jS", $startTime);
echo "<br />Time:" . date("g:i a", $startTime) . " - " . date("g:i a", $endTime) . "<br />";
@$db->query("INSERT OR IGNORE INTO `events` (eid, start_time, end_time, name, description) VALUES " . "('" . $eventObj->id . "'," . "'" . $eventObj->start_time . "'," . "'" . $eventObj->end_time . "'," . "'" . $eventObj->name . "'," . "'" . $eventObj->intro . "');");
}
$eventRes = @$db->query("SELECT * FROM `events`");
while ($event = $eventRes->fetchArray()) {
$json = pullUrl("https://techspring.nationbuilder.com/api/v1/sites/v2/pages/events/" . $event['eid'] . "/rsvps?limit=10&__proto__=&access_token=" . $token);
$rsvpData = json_decode($json);
foreach ($rsvpData->results as $rsvp) {
@$db->query("INSERT OR IGNORE INTO `rsvp` (eid, uid) VALUES ('" . $event['eid'] . "','" . $rsvp->person_id . "')");
}
}
}
开发者ID:TridentSoftware,项目名称:signin,代码行数:28,代码来源:update_database.php
示例18: read
public function read($params, AccountWriter $writer)
{
$args = new FormattedArgumentMap($params);
$folder = $args->opt("i", "plugins/SimpleAuth");
if (!is_dir($folder)) {
throw new \InvalidArgumentException("Input database {$folder} not found or is not a directory");
}
$path = rtrim($folder, "/\\") . "/players.db";
if (!is_file($path)) {
return;
}
$this->setStatus("Opening database");
$db = new \SQLite3($path);
$result = $db->query("SELECT COUNT(*) AS cnt FROM players");
$total = $result->fetchArray(SQLITE3_ASSOC)["cnt"];
$result->finalize();
$this->setStatus("Preparing data");
$result = $db->query("SELECT name,registerdate,logindate,lastip,hash FROM players");
$i = 0;
while (is_array($row = $result->fetchArray(SQLITE3_ASSOC))) {
$i++;
$info = AccountInfo::defaultInstance($row["name"], $this->defaultOpts);
$info->lastIp = $row["lastip"];
$info->registerTime = $row["registerdate"];
$info->lastLogin = $row["logindate"];
$info->passwordHash = hex2bin($row["hash"]);
$writer->write($info);
$this->setProgress($i / $total);
}
$db->close();
}
开发者ID:PEMapModder,项目名称:HereAuth,代码行数:31,代码来源:SimpleAuthSQLite3AccountReader.php
示例19: resetHighscore
function resetHighscore()
{
$db = new SQLite3('pacman.db');
$date = date('Y-m-d h:i:s', time());
$db->exec('DROP TABLE IF EXISTS highscore');
createDataBase($db);
}
开发者ID:luisrochadev,项目名称:pacman-canvas,代码行数:7,代码来源:db-handler.php
示例20: createDatabase
/**
* create a new database
*
* @param string $name name of the database that should be created
* @param array $options array with charset info
*
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function createDatabase($name, $options = array())
{
$datadir = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data");
$db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$database_file = $db->_getDatabaseFile($name);
if (file_exists($database_file)) {
return $db->raiseError(MDB2_ERROR_ALREADY_EXISTS, null, null, 'database already exists', __FUNCTION__);
}
$php_errormsg = '';
$database_file = "{$datadir}/{$database_file}.db";
$handle = new SQLite3($database_file);
if (!$handle) {
return $db->raiseError(MDB2_ERROR_CANNOT_CREATE, null, null, isset($php_errormsg) ? $php_errormsg : 'could not create the database file', __FUNCTION__);
}
//sqlite doesn't support the latin1 we use
// if (!empty($options['charset'])) {
// $query = 'PRAGMA encoding = ' . $db->quote($options['charset'], 'text');
// $handle->exec($query);
// }
$handle->close();
return MDB2_OK;
}
开发者ID:jaeindia,项目名称:ownCloud-Enhancements,代码行数:34,代码来源:sqlite3.php
注:本文中的SQLite3类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论