/** * 执行mysql query()操作 * @param string $sql * @return mixed */ public function query($sql) { // 是否记录 SQL log if (true == C('sql_log')) { wlog('SQL-Log', $sql); } $error_msg = ''; $_key = strtolower(substr($sql, 0, 6)); if ($_key == 'select') { $rs = sqlite_query($this->db, $sql, SQLITE_BOTH, $error_msg); } else { $rs = sqlite_exec($this->db, $sql, $error_msg); } if (!empty($rs)) { $GLOBALS['run_dbquery_count']++; return $rs; } else { if (C('show_errors')) { show_error('执行sqlite_query()出现错误: ' . $error_msg . '<br />原SQL: ' . $sql); } else { exit('db_sqlite2::query() error.'); } } //return false; }
/** * 結果を返さないクエリを実行する。 * * @param string $query SQL文。 * @return void */ function exec($query) { $result = sqlite_exec($this->link, $query); if ($result == false) { throw new DBException('クエリを実行できませんでした。', $query, $this->link); } }
function exec($query) { $this->error = ""; if ($this->versi == 3) { return $this->db->exec($query); } else { return sqlite_exec($this->db, $query, $this->error); } }
/** * 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; }
public function hasListing($a_sListingURL) { $l_sTmp = md5($a_sListingURL); $result = sqlite_query($this->db, "SELECT * FROM listings WHERE l_id = '" . $l_sTmp . "'"); $rows = sqlite_num_rows($result); if ($rows < 1) { $result = sqlite_exec($this->db, "INSERT INTO listings VALUES ('{$l_sTmp}')"); return false; } else { return true; } }
public function execute($sql, $params = array()) { foreach ($params as $k => $v) { $sql = str_replace(':' . $k, $this->escape($v), $sql); } $this->sql = $sql; if ($query = sqlite_exec($this->_getWriteLink(), $sql, $error_msg)) { return $query; } else { $this->error($error_msg); } }
public function exec($sql, $connResource) { if (empty($sql)) { return 0; } sqlite_exec($connResource, $sql); // echo '<pre>'; // print_r(debug_backtrace()); // debug_print_backtrace(); // echo '</pre>'; // delete from table 结果为0,原因未知。 // 使用 delete from table where 1 能返回正确结果 return sqlite_changes($connResource); }
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); } } }
public function exec($sql) { if (strtolower(substr($sql, 0, 6)) == 'select') { $res = sqlite_query($this->dbcon, $sql, SQLITE_BOTH, $error_msg); if ($error_msg) { echo 'Query Error: ' . $error_msg; } } else { $res = sqlite_exec($this->dbcon, $sql, $error_msg); if ($error_msg) { echo 'Query Error: ' . $error_msg; } } return $res; }
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; }
function connect() { if (!file_exists(FILE)) { $initReq = true; } $GLOBALS['sqlConnect'] = sqlite_open(FILE, 0666); if (!$GLOBALS['sqlConnect']) { return false; } if ($initReq) { $initSQL = "CREATE TABLE wwwsqldesigner (\r\n keyword varchar(30) NOT NULL default '',\r\n data TEXT ,\r\n dt DATETIME DEFAULT CURRENT_TIMESTAMP ,\r\n PRIMARY KEY ( keyword )\r\n );"; $res = sqlite_exec($initSQL, $GLOBALS['sqlConnect']); return $res; } return true; }
public function setup($cacheinfo) { //check if the db has been setup $this->cachebase = "app/cache/"; if (!empty($cacheinfo)) { $this->cachefile = $cacheinfo['dbname']; } $this->cachefile = $this->cachebase . $this->cachefile; if (!file_exists($this->cachefile)) { $this->cachedb = sqlite_open($this->cachefile, 0666); sqlite_exec("create table cache ( marker VARCHAR PRIMARY KEY, content TEXT, modified INT, valid INT, expired INTEGER DEFAULT 0) ", $this->cachedb); //sqlite_exec("create index marker on cache (marker) ",$this->cachedb); } else { $this->cachedb = sqlite_open($this->cachefile, 0666); } }
public static function open() { // connect $error_msg = null; define('SESSION_DB_LINK', sqlite_open(DIR_DATA . '/sessions.db', 0666, $error_msg)); if (!SESSION_DB_LINK) { warning("Can't open session database: {$error_msg}"); return false; } // check if required table exists, create it if necessary $R = sqlite_query("SELECT name FROM sqlite_master WHERE type='table' AND name='sess'", SESSION_DB_LINK); if (!sqlite_num_rows($R)) { sqlite_exec("CREATE TABLE sess (id TEXT, data TEXT, expire INT)", SESSION_DB_LINK); } return true; }
public function login($user, $password, $stayloggedin = false) { $user = sqlite_escape_string($user); $password = md5($salt . $password); $q = "SELECT * FROM users WHERE username = '******' AND password = '******' LIMIT 1"; $res = sqlite_query($this->db, $q, $e); if (sqlite_num_rows($res) > 0) { if ($stayloggedin) { $r = sqlite_fetch_array($res); setcookie("userid", $r['uid'], time() + 60 * 60 * 24 * 30); setcookie("pass", $password, time() + 60 * 60 * 24 * 30); } $_SESSION['uid'] = $r['uid']; $_SESSION['uname'] = $r['username']; $time = time(); $id = $r['uid']; sqlite_exec($this->db, "UPDATE users SET lastlogin = '******' WHERE uid = '{$id}'", $e); return true; } return false; }
public function exec($query) { # This method executes a query. # @param string $query # @return boolean global $sqlite, $syslog; ob_start(); // Start catching error messages if (sqlite_exec($sqlite->handle, $query)) { ob_end_clean(); $syslog->success('SQLObject', 'exec()', $query); return true; } else { $this->error = strip_tags(ob_get_contents(), '<strong><b>'); // Get the error message from the buffer $this->sqlite_error = sqlite_error_string(sqlite_last_error($sqlite->handle)); // Get the error message of the error code ob_end_clean(); $syslog->error('SQLObject', 'exec()', $query, $this->sqlite_error); return false; } }
function __construct($sqlite_data) { global $design_hidden; $this->data=$sqlite_data; if($design_hidden) $this->data[debug]=0; $init_necessary=0; if((!file_exists($this->data['file']))||(filesize($this->data['file'])==0)) { $init_necessary=1; } if(!$this->linkid=sqlite_open($this->data['file'])) { echo "Fehler beim Verbindungsaufbau!<br>"; exit; } if($init_necessary) { sqlite_exec($this->linkid, file_get_contents("init.sql")); } return 1; }
} $row = @sqlite_fetch_array($result, SQLITE_ASSOC); if ($row['userType'] != 'admin') { //If session not registered header("location:login.php?msg=You must be an admin to access this page."); // Redirect to login.php page } else { //Continue to current page header('Content-Type: text/html; charset=utf-8'); } // Begin the process of adding a department // If no object has been selected to be added... if (!isset($_GET['objectType'])) { echo '<p>Error: No object to be added.</p>'; sqlite_close($db); die; } if (!($_GET['objectType'] == "Department" && isset($_GET['departmentName']) && isset($_GET['iconID']))) { echo '<p>Error: Please fill all fields.</p>'; sqlite_close($db); die; } $insert_sql = "INSERT INTO Department (deptName, iconID) VALUES (\"" . $_GET['departmentName'] . "\",\"" . $_GET['iconID'] . "\")"; $insert = sqlite_exec($db, $insert_sql, $sqliteError); if (!$insert) { //if the insertion failed for any reason... sqlite_close($db); die($sqliteError); } echo '<p>' . $_GET['departmentName'] . '<br/>Department added. Please refresh your browser before continuing.</p>'; sqlite_close($db);
$db_string = '("' . $lastid . '", "' . $lastpage . '", "' . $last['lang'] . '", "' . $last['date'] . '", "' . $lastemail . '", "' . $last['display'] . '", "' . $last['note'] . '")'; sqlite_close($queuedb); $flag = true; } } if ($flag) { $notesdb = sqlite_open($notesfile); $result = sqlite_exec($notesdb, "INSERT INTO notes VALUES {$db_string}"); sqlite_close($notesdb); if (!$result) { /* Not being able to write to the notes db is pretty worrying. errorcode GTK_888 */ $errcode = "GTK_888"; file_put_contents($stats, "{$errcode}:{$lastid} held in queue (write failed)\n", FILE_APPEND); } else { $queuedb = sqlite_open($queuefile); $result = sqlite_exec($queuedb, "DELETE FROM notes WHERE id = {$lastid}"); sqlite_close($queuedb); if (!$result) { /* Not being able to write to the queue isn't great either. errorcode GTK_777 */ $errcode = "GTK_777"; file_put_contents($stats, "{$errcode}:{$lastid} not deleted from queue\n", FILE_APPEND); } /* Mail the user to confirm good stuff */ if ($errcode != 'GTK_888' && !strstr($last['email'], "GTK_000") || isset($_COOKIE[$user])) { $msg = "Hi\n\nThis is to confirm that your PHP-GTK manual note reached the top of the queue and will be available for viewing shortly at <a href='{$referrer}'>{$referrer}</a>.\n\nThank you again for your contribution!\n\nRegards,\nThe PHP-GTK Documentation Group"; if (isset($_COOKIE[$user])) { $lastemail = $_COOKIE[$user]; } if ($mail) { mail($lastemail, "PHP-GTK Manual Note {$lastid} added", $msg, "From: {$mailfrom}"); }
/** * Envoie une commande ROLLBACK à la base de données pour annulation de la * transaction courante * * @access public * @return boolean */ function rollBack() { return sqlite_exec($this->link, 'ROLLBACK'); }
/** * Returns SQLite resource. * @return resource */ protected function getDb() { if ($this->db === NULL) { if (!extension_loaded('sqlite')) { throw new InvalidStateException("SQLite extension is required for storing tags and priorities."); } $this->db = sqlite_open($this->dir . '/cachejournal.sdb'); @sqlite_exec($this->db, 'CREATE TABLE cache (file VARCHAR NOT NULL, priority, tag VARCHAR); CREATE INDEX IDX_FILE ON cache (file); CREATE INDEX IDX_PRI ON cache (priority); CREATE INDEX IDX_TAG ON cache (tag);'); // @ - table may already exist } return $this->db; }
/** * Executes a SQL statement * * @param string|fStatement $statement The statement to perform * @param array $params The parameters for prepared statements * @return void */ private function perform($statement, $params) { fCore::startErrorCapture(); $extra = NULL; if (is_object($statement)) { $result = $statement->execute($params, $extra, $statement != $this->statement); } elseif ($this->extension == 'ibm_db2') { $result = db2_exec($this->connection, $statement, array('cursor' => DB2_FORWARD_ONLY)); } elseif ($this->extension == 'mssql') { $result = mssql_query($statement, $this->connection); } elseif ($this->extension == 'mysql') { $result = mysql_unbuffered_query($statement, $this->connection); } elseif ($this->extension == 'mysqli') { $result = mysqli_query($this->connection, $statement, MYSQLI_USE_RESULT); } elseif ($this->extension == 'oci8') { $extra = oci_parse($this->connection, $statement); $result = oci_execute($extra, $this->inside_transaction ? OCI_DEFAULT : OCI_COMMIT_ON_SUCCESS); } elseif ($this->extension == 'pgsql') { $result = pg_query($this->connection, $statement); } elseif ($this->extension == 'sqlite') { $result = sqlite_exec($this->connection, $statement, $extra); } elseif ($this->extension == 'sqlsrv') { $result = sqlsrv_query($this->connection, $statement); } elseif ($this->extension == 'pdo') { if ($this->type == 'mssql' && !fCore::checkOS('windows')) { // pdo_dblib is all messed up for return values from ->exec() // and even ->query(), but ->query() is closer to correct and // we use some heuristics to overcome the limitations $result = $this->connection->query($statement); if ($result instanceof PDOStatement) { $result->closeCursor(); $extra = $result; $result = TRUE; if (preg_match('#^\\s*EXEC(UTE)?\\s+#i', $statement)) { $error_info = $extra->errorInfo(); if (strpos($error_info[2], '(null) [0] (severity 0)') !== 0) { $result = FALSE; } } } } else { $result = $this->connection->exec($statement); } } $this->statement = $statement; $this->handleErrors(fCore::stopErrorCapture()); // The mssql extension will sometimes not return FALSE even if there are errors if (strlen($this->error)) { $result = FALSE; } if ($this->extension == 'mssql' && $result) { $this->error = ''; } if ($result === FALSE) { $this->checkForError($result, $extra, is_object($statement) ? $statement->getSQL() : $statement); } elseif (!is_bool($result) && $result !== NULL) { if ($this->extension == 'ibm_db2') { db2_free_result($result); } elseif ($this->extension == 'mssql') { mssql_free_result($result); } elseif ($this->extension == 'mysql') { mysql_free_result($result); } elseif ($this->extension == 'mysqli') { mysqli_free_result($result); } elseif ($this->extension == 'oci8') { oci_free_statement($oci_statement); } elseif ($this->extension == 'pgsql') { pg_free_result($result); } elseif ($this->extension == 'sqlsrv') { sqlsrv_free_stmt($result); } } }
function updatestate($db, $id, $newstate) { $q = 'UPDATE Logs SET state=' . $newstate . ' WHERE id=' . $id . ';'; $ok = sqlite_exec($db, $q, $error); if (!$ok) { die("Cannot execute query. {$error}"); } }
/** * Execute the query * * @param string $sql an SQL query * @return resource */ protected function _execute($sql) { return $this->is_write_type($sql) ? sqlite_exec($this->conn_id, $sql) : sqlite_query($this->conn_id, $sql); }
/** * 执行语句 * @access public * @param string $str sql指令 * @return integer */ public function execute($str) { $this->initConnect(true); if ( !$this->_linkID ) return false; $this->queryStr = $str; //释放前次的查询结果 if ( $this->queryID ) $this->free(); N('db_write',1); // 记录开始执行时间 G('queryStartTime'); $result = sqlite_exec($this->_linkID,$str); $this->debug(); if ( false === $result ) { $this->error(); return false; } else { $this->numRows = sqlite_changes($this->_linkID); $this->lastInsID = sqlite_last_insert_rowid($this->_linkID); return $this->numRows; } }
()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n) ?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<> @,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@, ;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t] )*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\ ".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)? (?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\". \[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?: \r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\[ "()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t]) *))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t]) +|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\ .(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z |(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:( ?:\r\n)?[ \t])*))*)?;\s*)/ EOT; if (0 == preg_match($email_regex, $_REQUEST['email'])) { $msg .= "Error: The new e-mail address is not valid."; } else { $update_sql = "UPDATE User JOIN Personnel ON EmployeeID SET Email = \"" . $_REQUEST['email'] . "\" WHERE username = \"" . $_SESSION['name'] . "\""; $result = sqlite_exec($db, $update_sql, $sqliteerror); if (false == $result) { sqlite_close($db); die($sqliteerror . ", please try again."); } $msg .= "E-mail address was changed successfully!"; } } header("location:settings.php?msg=" . $msg); sqlite_close($db);
function Update($SqlBuilder, $SenderObject, $SenderMethod, $ErrorMessage, $KillOnFail = '1') { $KillOnFail = ForceBool($KillOnFail, 0); $Connection = $this->GetFarmConnection(); if (!sqlite_exec($Connection, $SqlBuilder->GetUpdate())) { $this->Context->ErrorManager->AddError($SqlBuilder->Context, $SenderObject, $SenderMethod, $ErrorMessage, sqlite_error_string(sqlite_last_error($this->Connection)), $KillOnFail); return false; } else { return sqlite_changes($Connection); } }
/** * Elimina un elemento de la cache * * @param string $id * @param string $group * @return boolean */ public function remove($id, $group = 'default') { $id = addslashes($id); $group = addslashes($group); return sqlite_exec($this->_db, " DELETE FROM cache WHERE id='{$id}' AND \"group\"='{$group}' "); }
<?php // set values $id = $_GET['id']; $title = $_POST['title']; $speaker = $_POST['speaker']; $date = $_POST['date']; $url = $_POST['url']; $type = $_POST['type']; $sqldb = sqlite_open("../db/nvc.db") or die("Could not connect!"); $queryStr = "update sermon set stitle='{$title}', speaker='{$speaker}', date='{$date}', url='{$url}', type='{$type}' where id={$id}"; sqlite_exec($sqldb, $queryStr); sqlite_close($sqldb); header('Location: sermon.php'); ?>
/** * Executes a SQL statement * * @param string|fStatement $statement The statement to perform * @param array $params The parameters for prepared statements * @return void */ private function perform($statement, $params) { fCore::startErrorCapture(); $extra = NULL; if (is_object($statement)) { $result = $statement->execute($params, $extra, $statement != $this->statement); } elseif ($this->extension == 'ibm_db2') { $result = db2_exec($this->connection, $statement, array('cursor' => DB2_FORWARD_ONLY)); } elseif ($this->extension == 'mssql') { $result = mssql_query($statement, $this->connection); } elseif ($this->extension == 'mysql') { $result = mysql_unbuffered_query($statement, $this->connection); } elseif ($this->extension == 'mysqli') { $result = mysqli_query($this->connection, $statement, MYSQLI_USE_RESULT); } elseif ($this->extension == 'oci8') { $extra = oci_parse($this->connection, $statement); $result = oci_execute($extra, $this->inside_transaction ? OCI_DEFAULT : OCI_COMMIT_ON_SUCCESS); } elseif ($this->extension == 'pgsql') { $result = pg_query($this->connection, $statement); } elseif ($this->extension == 'sqlite') { $result = sqlite_exec($this->connection, $statement, $extra); } elseif ($this->extension == 'sqlsrv') { $result = sqlsrv_query($this->connection, $statement); } elseif ($this->extension == 'pdo') { if ($this->type == 'mssql' && !fCore::checkOS('windows')) { $result = $this->connection->query($statement); if ($result instanceof PDOStatement) { $result->closeCursor(); } } else { $result = $this->connection->exec($statement); } } $this->statement = $statement; $this->handleErrors(fCore::stopErrorCapture()); if ($result === FALSE) { $this->checkForError($result, $extra, is_object($statement) ? $statement->getSQL() : $statement); } elseif (!is_bool($result) && $result !== NULL) { if ($this->extension == 'ibm_db2') { db2_free_result($result); } elseif ($this->extension == 'mssql') { mssql_free_result($result); } elseif ($this->extension == 'mysql') { mysql_free_result($result); } elseif ($this->extension == 'mysqli') { mysqli_free_result($result); } elseif ($this->extension == 'oci8') { oci_free_statement($oci_statement); } elseif ($this->extension == 'pgsql') { pg_free_result($result); } elseif ($this->extension == 'sqlsrv') { sqlsrv_free_stmt($result); } } }
flush(); $fields = array(); $result = sqlite_query($fs, "PRAGMA table_info({$table})"); for ($i = 0, $m = sqlite_num_rows($result); $i < $m; $i++) { sqlite_seek($result, $i); array_push($fields, sqlite_column($result, 'name')); } $fields = implode(', ', $fields); $result = $db->query("SELECT {$fields} FROM {$table}"); $result->setFetchMode(SQL_FETCH_NUM); $numrows = 0; while ($row = $result->fetch()) { $values = array(); $numrows++; foreach ($row as $value) { if (is_null($value)) { $value = 'NULL'; } else { $value = "'" . sqlite_escape_string($value) . "'"; } array_push($values, $value); } sqlite_exec($fs, "INSERT INTO {$table} ({$fields}) VALUES(" . implode(", ", $values) . ")"); } printf("%d rows added.\n", $numrows); flush(); } sqlite_close($fs); $db->close(); echo "\nSQLite database has been successfully initialized!\n"; exit(0);