function getOneColumnAsArray() { $column = array(); $queryId = $this->connection->execute($this->getSQL()); while ($value = sqlite_fetch_single($queryId)) { $column[] = $value; } return $column; }
/** * Constructor */ public function __construct() { //Abre una conexión SqLite a la base de datos cache $this->_db = sqlite_open(':memory:'); $result = sqlite_query($this->_db, "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND tbl_name='cache' "); $count = sqlite_fetch_single($result); if (!$count) { sqlite_exec($this->_db, ' CREATE TABLE cache (id TEXT, "group" TEXT, value TEXT, lifetime TEXT) '); } return $this->_db; }
function loadTables() { if ($this->isExisting) { $sql = "SELECT name FROM sqlite_master WHERE type='table' UNION ALL " . "SELECT name FROM sqlite_temp_master WHERE type='table' ORDER BY name;"; $queryId = $this->connection->execute($sql); while (sqlite_has_more($queryId)) { $this->tables[sqlite_fetch_single($queryId)] = null; } $this->isTablesLoaded = true; } }
/** * Get redirect route * * @param string $onMatchCondition (rejectCall | acceptCall) * @return string returns the SIP URL * @author John Dyer */ function getRedirectRoute($onMatchCondition){ global $dbPath; $dbhandle = sqlite_open($dbPath,0666); if ($onMatchCondition == "rejectCall"){ $sql = sqlite_query($dbhandle,"select value from data where id='rejectRedirectURL'"); $url = sqlite_fetch_single($sql); }elseif ($onMatchCondition == "acceptCall"){ $sql = sqlite_query($dbhandle,"select value from data where id='acceptRedirectURL'"); $url = sqlite_fetch_single($sql); } // print ('<redirectRoute>' . urldecode($url) . '</redirectRoute>'); return urldecode($url); }
function insertid() { if ($this->handler) { $response = sqlite_query($this->handler, 'SELECT last_insert_rowid()'); if ($response) { return sqlite_fetch_single($response); } else { return false; } } else { die('データベースハンドラが見つかりません。'); } }
/** * raw_db_list_database_tables() * Returns an array with the list of tables of the current database. * * @return array or FALSE */ function raw_db_list_database_tables() { global $g_current_db; $tables = array(); $sql = "SELECT name FROM sqlite_master WHERE (type = 'table')"; $res = sqlite_query($g_current_db, $sql); if ($res) { while (sqlite_has_more($res)) { $tables[] = sqlite_fetch_single($res); } } else { return false; } return $tables; }
public function get($name) { $this->Q(1); $name = sqlite_escape_string($name); $sql = 'SELECT ' . $this->options['value'] . ' FROM ' . $this->options['table'] . ' WHERE ' . $this->options['var'] . '=\'' . $name . '\' AND (' . $this->options['expire'] . '=-1 OR ' . $this->options['expire'] . '>' . time() . ') LIMIT 1'; $result = sqlite_query($this->handler, $sql); if (sqlite_num_rows($result)) { $content = sqlite_fetch_single($result); if (C('DATA_CACHE_COMPRESS') && function_exists('gzcompress')) { $content = gzuncompress($content); } return unserialize($content); } return false; }
/** * 读取缓存 * @access public * @param string $name 缓存变量名 * @param mixed $default 默认值 * @return mixed */ public function get($name, $default = false) { $name = $this->getCacheKey($name); $sql = 'SELECT value FROM ' . $this->options['table'] . ' WHERE var=\'' . $name . '\' AND (expire=0 OR expire >' . $_SERVER['REQUEST_TIME'] . ') LIMIT 1'; $result = sqlite_query($this->handler, $sql); if (sqlite_num_rows($result)) { $content = sqlite_fetch_single($result); if (function_exists('gzcompress')) { //启用数据压缩 $content = gzuncompress($content); } return unserialize($content); } return $default; }
function formthrottle_too_many_submissions($ip) { $tooManySubmissions = false; if (function_exists("sqlite_open") and $db = @sqlite_open('muse-throttle-db', 0666, $sqliteerror)) { $ip = @sqlite_escape_string($ip); @sqlite_exec($db, "DELETE FROM Submission_History WHERE Submission_Date < DATETIME('now','-2 hours')", $sqliteerror); @sqlite_exec($db, "INSERT INTO Submission_History (IP,Submission_Date) VALUES ('{$ip}', DATETIME('now'))", $sqliteerror); $res = @sqlite_query($db, "SELECT COUNT(1) FROM Submission_History WHERE IP = '{$ip}';", $sqliteerror); if (@sqlite_num_rows($res) > 0 and @sqlite_fetch_single($res) > 25) { $tooManySubmissions = true; } @sqlite_close($db); } return $tooManySubmissions; }
public function add($ip, $comment) { $comment = self::trunc($comment); $ip = "'" . sqlite_escape_string($ip) . "'"; if ($comment == '') { sqlite_exec($this->handle, "delete from comments where ip=" . $ip, $this->error); } else { $comment = "'" . sqlite_escape_string($comment) . "'"; if (($query = sqlite_unbuffered_query($this->handle, "select count(comment) from comments where ip=" . $ip, SQLITE_ASSOC, $this->error)) && sqlite_fetch_single($query)) { sqlite_exec($this->handle, "update comments set comment=" . $comment . " where ip=" . $ip, $this->error); } else { sqlite_exec($this->handle, "insert into comments (ip,comment) values (" . $ip . "," . $comment . ")", $this->error); } } }
/** * 读取缓存 * @access public * @param string $name 缓存变量名 * @return mixed */ public function get($name) { $name = $this->options['prefix'] . sqlite_escape_string($name); $sql = 'SELECT value FROM ' . $this->options['table'] . ' WHERE var=\'' . $name . '\' AND (expire=0 OR expire >' . time() . ') LIMIT 1'; $result = sqlite_query($this->handler, $sql); if (sqlite_num_rows($result)) { $content = sqlite_fetch_single($result); if (function_exists('gzcompress')) { //启用数据压缩 $content = gzuncompress($content); } return unserialize($content); } return false; }
function getLabel($url) { $dbhandle = sqlite_open('labelcache.db'); if (!sqlite_has_more(sqlite_query($dbhandle, "SELECT name FROM sqlite_master WHERE name='labels'"))) { sqlite_query($dbhandle, "CREATE TABLE labels (url,label)"); } $query = sqlite_query($dbhandle, 'SELECT label FROM labels WHERE url="' . $url . '"'); $result = sqlite_fetch_single($query, SQLITE_ASSOC); if (empty($result)) { $label = retrieveLabel($url); sqlite_query($dbhandle, "INSERT INTO labels (url,label) VALUES ('{$url}','" . sqlite_escape_string($label) . "');"); return $label; } else { return $result; } }
/** * Guarda un elemento en la cache con nombre $id y valor $value * * @param string $id * @param string $group * @param string $value * @param int $lifetime tiempo de vida en forma timestamp de unix * @return boolean */ public function save($id, $group, $value, $lifetime) { if ($lifetime == null) { $lifetime = 'undefined'; } $id = addslashes($id); $group = addslashes($group); $value = addslashes($value); $result = sqlite_query($this->_db, " SELECT COUNT(*) FROM cache WHERE id='{$id}' AND \"group\"='{$group}' "); $count = sqlite_fetch_single($result); /** * Ya existe el elemento cacheado * **/ if ($count) { return sqlite_exec($this->_db, " UPDATE cache SET value='{$value}', lifetime='{$lifetime}' WHERE id='{$id}' AND \"group\"='{$group}' "); } return sqlite_exec($this->_db, " INSERT INTO cache (id, \"group\", value, lifetime) VALUES ('{$id}','{$group}','{$value}','{$lifetime}') "); }
/** * Handles the page write event and removes the database info * when the plugin code is no longer in the source */ function _handle(&$event, $param) { $data = $event->data; if (strpos($data[0][1], 'dataentry') !== false) { return; } // plugin seems still to be there $sqlite = $this->dthlp->_getDB(); if (!$sqlite) { return; } $id = ltrim($data[1] . ':' . $data[2], ':'); // get page id $res = $sqlite->query('SELECT pid FROM pages WHERE page = ?', $id); $pid = (int) sqlite_fetch_single($res); if (!$pid) { return; } // we have no data for this page $sqlite->query('DELETE FROM data WHERE pid = ?', $pid); $sqlite->query('DELETE FROM pages WHERE pid = ?', $pid); }
/** * Clean some cache records * * Available modes are : * Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used) * Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used) * Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags * ($tags can be an array of strings or a single string) * Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags} * ($tags can be an array of strings or a single string) * * @param string $mode Clean mode * @param array $tags Array of tags * @return boolean True if no problem */ private function _clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) { if ($mode == Zend_Cache::CLEANING_MODE_ALL) { $res1 = $this->_query('DELETE FROM cache'); $res2 = $this->_query('DELETE FROM tag'); return $res1 && $res2; } if ($mode == Zend_Cache::CLEANING_MODE_OLD) { $mktime = time(); $res1 = $this->_query("DELETE FROM tag WHERE id IN (SELECT id FROM cache WHERE expire>0 AND expire<={$mktime})"); $res2 = $this->_query("DELETE FROM cache WHERE expire>0 AND expire<={$mktime}"); return $res1 && $res2; } if ($mode == Zend_Cache::CLEANING_MODE_MATCHING_TAG) { $first = true; $ids = array(); foreach ($tags as $tag) { $res = $this->_query("SELECT DISTINCT(id) AS id FROM tag WHERE name='{$tag}'"); if (!$res) { return false; } $rows = @sqlite_fetch_all($res, SQLITE_ASSOC); $ids2 = array(); foreach ($rows as $row) { $ids2[] = $row['id']; } if ($first) { $ids = $ids2; $first = false; } else { $ids = array_intersect($ids, $ids2); } } $result = true; foreach ($ids as $id) { $result = $result && $this->remove($id); } return $result; } if ($mode == Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG) { $res = $this->_query("SELECT id FROM cache"); $rows = @sqlite_fetch_all($res, SQLITE_ASSOC); $result = true; foreach ($rows as $row) { $id = $row['id']; $matching = false; foreach ($tags as $tag) { $res = $this->_query("SELECT COUNT(*) AS nbr FROM tag WHERE name='{$tag}' AND id='{$id}'"); if (!$res) { return false; } $nbr = (int) @sqlite_fetch_single($res); if ($nbr > 0) { $matching = true; } } if (!$matching) { $result = $result && $this->remove($id); } } return $result; } return false; }
/** * Load data from SQLite database. * * @return mixed */ public function load() { $this->setSqlite(); $this->clean(); $statement = 'SELECT data FROM hoa_cache ' . "\n" . 'WHERE id = \'' . sqlite_escape_string($this->getIdMd5()) . '\''; $query = sqlite_query($statement, $this->getSqlite()); if (0 === sqlite_num_rows($query)) { return false; } $content = sqlite_fetch_single($query); if (true === $this->_parameters->getParameter('serialize_content')) { $content = unserialize($content); } return $content; }
unlink($queuefile); } clearstatcache(); if (!file_exists($queuefile)) { $db = sqlite_open($queuefile); sqlite_query($db, "BEGIN;\n\t\t\tCREATE TABLE notes( \n\t\t\t\tid INTEGER PRIMARY KEY, \n\t\t\t\tpage CHAR(100), \n\t\t\t\tlang CHAR(5),\n\t\t\t\tdate INT(11), \n\t\t\t\temail CHAR(700), \n\t\t\t\tdisplay CHAR(700),\n\t\t\t\tcomment CHAR(4000)); \n\t\t\tCOMMIT;"); sqlite_close($db); } /* check for/create the last_id file while we're at it */ if (!file_exists($last_id) || !file_get_contents($last_id) || file_get_contents($last_id == '0')) { $db = sqlite_open($notesfile); $estimate = sqlite_single_query($db, "SELECT COUNT(*) FROM notes"); $setid = sqlite_query($db, "SELECT id FROM notes WHERE id > '{$estimate}'", SQLITE_ASSOC); if ($setid && sqlite_num_rows($setid) > 0) { while (sqlite_valid($setid)) { $rowid = sqlite_fetch_single($setid); } } else { $rowid = $estimate; } file_put_contents($last_id, $rowid); sqlite_close($db); } } /* ============================ PREVIEW ONLY ========================= */ if (isset($_POST['preview'])) { print "<br />\n<p>\nThis is what your entry will look like, roughly:\n</p>\n"; print "<table border='0' cellpadding='0' cellspacing='0' width='100%' align = 'center'>\n"; $temp = array('display' => $display, 'comment' => htmlentities($content), 'date' => time()); makeEntry($temp, false); print "</table>\n";
<?php $dbhandle = sqlite_open('log'); if ($dbhandle == false) { die('Unable to open database'); } else { echo 'Database created.'; } $dbquery = ' SELECT * FROM tbl1'; $dbresult = sqlite_query($dbhandle, $dbquery); while (sqlite_has_more($dbresult)) { $dbrow = sqlite_fetch_single($dbquery); print_r($dbrow); } sqlite_close($dbhandle);
/** * Return the first value from the first row. */ function res2single($res) { if ($this->extension == DOKU_EXT_SQLITE) { return sqlite_fetch_single($res); } else { if (!$res) { return false; } $data = $res->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_ABS, 0); if (!count($data)) { return false; } return $data[0]; } }
function sqlitem_fetch_single($result, $result_type = SQLITE_BOTH, $decode_binary = TRUE) { return sqlite_fetch_single($result, $result_type, $decode_binary); }
public function lastModified($id, $namespace = self::DEFAULT_NAMESPACE) { $statement = sprintf("SELECT created_at FROM cache WHERE id = '%s' AND namespace = '%s'", sqlite_escape_string($id), sqlite_escape_string($namespace)); $rs = sqlite_query($statement, $this->conn); return sqlite_num_rows($rs) ? intval(sqlite_fetch_single($rs)) : 0; }
/** * Fetches the first column of the first row of the SQL result. * * @param string| SQL SELECT statement. * @param mixed $bind Data to bind into SELECT placeholders. * @return string */ public function fetchOne($sql, $bind = array()) { $result = null; $result = $this->query($sql, $bind); $field_value = @sqlite_fetch_single($result); return self::_stripQuote($field_value); }
/** * Returns the next ID of a table * * @param string the name of the table * @param string the name of the ID column * @return int */ public function nextID($table, $id) { $result = $this->query('SELECT max(' . $id . ') AS current_id FROM ' . $table); $currentID = intval(sqlite_fetch_single($result)); return $currentID + 1; }
/** * returns value of variable in shared mem * * @param string $name name of variable * * @return mixed value of the variable * @access public */ function get($name) { $name = sqlite_escape_string($name); $sql = 'SELECT ' . $this->_options['value'] . ' FROM ' . $this->_options['table'] . ' WHERE ' . $this->_options['var'] . '=\'' . $name . '\'' . ' LIMIT 1'; $result = sqlite_query($this->_h, $sql); if (sqlite_num_rows($result)) { return unserialize(sqlite_fetch_single($result)); } return null; }
/** * Retrieves catalogue details, array($cat_id, $variant, $count). * * @param string $catalogue catalogue * @return array catalogue details, array($cat_id, $variant, $count). */ protected function getCatalogueDetails($catalogue = 'messages') { if (empty($catalogue)) { $catalogue = 'messages'; } $variant = $catalogue . '.' . $this->culture; $name = sqlite_escape_string($this->getSource($variant)); $db = sqlite_open($this->source); $rs = sqlite_query("SELECT cat_id FROM catalogue WHERE name = '{$name}'", $db); if (sqlite_num_rows($rs) != 1) { return false; } $cat_id = intval(sqlite_fetch_single($rs)); // first get the catalogue ID $rs = sqlite_query("SELECT count(msg_id) FROM trans_unit WHERE cat_id = {$cat_id}", $db); $count = intval(sqlite_fetch_single($rs)); sqlite_close($db); return array($cat_id, $variant, $count); }
/** * Guarda un elemento en la cache con nombre $id y valor $value * * @param string $id * @param string $group * @param string $value * @param int $lifetime tiempo de vida en forma timestamp de unix * @return boolean */ public function save($value, $lifetime = '', $id = '', $group = 'default') { if (!$id) { $id = $this->_id; $group = $this->_group; } if ($lifetime) { $lifetime = strtotime($lifetime); } else { $lifetime = 'undefined'; } $id = addslashes($id); $group = addslashes($group); $value = addslashes($value); $result = sqlite_query($this->_db, " SELECT COUNT(*) FROM cache WHERE id='{$id}' AND \"group\"='{$group}' "); $count = sqlite_fetch_single($result); // Ya existe el elemento cacheado if ($count) { return sqlite_exec(" UPDATE cache SET value='{$value}', lifetime='{$lifetime}' WHERE id='{$id}' AND \"group\"='{$group}' ", $this->_db); } return sqlite_exec(" INSERT INTO cache (id, \"group\", value, lifetime) VALUES ('{$id}','{$group}','{$value}','{$lifetime}')", $this->_db); }
/** * Give (if possible) an extra lifetime to the given cache id * * @param string $id cache id * @param int $extraLifetime * @return boolean true if ok */ public function touch($id, $extraLifetime) { $sql = "SELECT expire FROM cache WHERE id='{$id}' AND (expire=0 OR expire>" . time() . ')'; $res = $this->_query($sql); if (!$res) { return false; } $expire = @sqlite_fetch_single($res); $newExpire = $expire + $extraLifetime; $res = $this->_query("UPDATE cache SET lastModified=" . time() . ", expire={$newExpire} WHERE id='{$id}'"); if ($res) { return true; } else { return false; } }
function check_if_exists($cc) { $result = sqlite_unbuffered_query("SELECT id FROM country_data WHERE cc_code_2='{$cc}'", sqlite_r); return sqlite_fetch_single($result); }
/** * Save date to the database */ function _saveData($data, $id, $title) { $sqlite = $this->dthlp->_getDB(); if (!$sqlite) { return false; } $error = ''; if (!$title) { $title = $id; } $class = $data['classes']; // begin transaction $sqlite->query("BEGIN TRANSACTION"); // store page info $sqlite->query("INSERT OR IGNORE INTO pages (page,title,class) VALUES (?,?,?)", $id, $title, $class); // Update title if insert failed (record already saved before) $revision = filemtime(wikiFN($id)); $sqlite->query("UPDATE pages SET title = ?, class = ?, lastmod = ? WHERE page = ?", $title, $class, $revision, $id); // fetch page id $res = $sqlite->query("SELECT pid FROM pages WHERE page = ?", $id); $pid = (int) sqlite_fetch_single($res); if (!$pid) { msg("data plugin: failed saving data", -1); return false; } // remove old data $sqlite->query("DELETE FROM data WHERE pid = ?", $pid); // insert new data foreach ($data['data'] as $key => $val) { if (is_array($val)) { foreach ($val as $v) { $sqlite->query("INSERT INTO data (pid, key, value) VALUES (?, ?, ?)", $pid, $key, $v); } } else { $sqlite->query("INSERT INTO data (pid, key, value) VALUES (?, ?, ?)", $pid, $key, $val); } } // finish transaction $sqlite->query("COMMIT TRANSACTION"); return true; }
function db_result($result, $row = 0) { if (sqlite2) { return sqlite_fetch_single($result); } if (sqlite3) { $rec = $result->fetchArray(SQLITE3_NUM); if ($rec === FALSE) { return FALSE; } return $rec[0]; } if (pdo_sqlite) { $rec = $result->fetch(PDO::FETCH_NUM); if ($rec === FALSE) { return FALSE; } return $rec[0]; } if (mysql) { if ($result && mysql_num_rows($result) > $row) { return mysql_result($result, $row); } } }