/** * The primary method a driver needs to implement is the execute method, which takes an array of query options. * The options in the array varies, but the key type will always be supplied, which will be either SELECT, UPDATE, * INSERT, REPLACE or DELETE. * * @param array $options An array of options that were generated through use of the Query class. * @return object It is expected to return an instance of an \Queryer\Driver\DatabaseDriverResult class. * @see \Queryer\Query, \Queryer\Driver\DatabaseDriverResult */ public function execute(array $options) { $query = self::generateQuery($options); $query = DatabaseTools::replaceVariables($query, $options['variables']); $result = $this->sqlite->query($query); return new Sqlite3DriverResult($result, $this->sqlite->changes(), $this->sqlite->lastInsertRowID(), $result === false ? $this->sqlite->lastErrorCode() : null, $result === false ? $this->sqlite->lastErrorMsg() : null, $query); }
/** * {@inheritdoc} */ protected function executeQuery($query, array $parameters) { if (isset($this->statements[$query])) { $statement = $this->statements[$query]; } else { // Temporary set the error reporting level to 0 to avoid any warning. $errorReportingLevel = error_reporting(0); $statement = $this->sqlite3->prepare($query); // Restore the original error reporting level. error_reporting($errorReportingLevel); $errorCode = $this->sqlite3->lastErrorCode(); if ($errorCode !== 0) { $exception = new SQLite3Exception($this->sqlite3->lastErrorMsg(), $errorCode); if ($errorCode === 1) { // SQL error cause by a missing function, this must be reported with a GeometryEngineException. throw GeometryEngineException::operationNotSupportedByEngine($exception); } else { // Other SQLite3 error; we cannot trigger the original E_WARNING, so we throw this exception instead. throw $exception; } } else { $this->statements[$query] = $statement; } } $index = 1; foreach ($parameters as $parameter) { if ($parameter instanceof Geometry) { if ($parameter->isEmpty()) { $statement->bindValue($index++, $parameter->asText(), SQLITE3_TEXT); $statement->bindValue($index++, $parameter->SRID(), SQLITE3_INTEGER); } else { $statement->bindValue($index++, $parameter->asBinary(), SQLITE3_BLOB); $statement->bindValue($index++, $parameter->SRID(), SQLITE3_INTEGER); } } else { if ($parameter === null) { $type = SQLITE3_NULL; } elseif (is_int($parameter)) { $type = SQLITE3_INTEGER; } elseif (is_float($parameter)) { $type = SQLITE3_FLOAT; } else { $type = SQLITE3_TEXT; } $statement->bindValue($index++, $parameter, $type); } } $result = $statement->execute(); return $result->fetchArray(SQLITE3_NUM); }
/** * Establishes a connection to the defined database. * * @return void */ public function connect() { if ($this->connected === TRUE) { return; } if ($this->configuration['db']['driver'] != 'sqlite3') { $this->logger->error('Cannot connect to a non-sqlite3 database connection!'); return; } $flag = $this->readonly ? SQLITE3_OPEN_READONLY : SQLITE3_OPEN_READWRITE; $this->sqlite3->open($this->db, $flag | SQLITE3_OPEN_CREATE, ''); if ($this->sqlite3->lastErrorCode() === 0) { $this->connected = TRUE; } }
/** * @param string $dbname database name * @param OutputInterface $output standard verbode output * @param boolean $renew if true delete and recreate database * * @throws \Exception */ public function __construct($dbname, OutputInterface $output, $renew = false) { $this->fs = new Filesystem(); $this->output = $output; $this->dbname = $dbname; if ($renew) { if ($this->fs->exists($this->dbname)) { $this->fs->remove($this->dbname); } } $this->db = new \SQLite3($this->dbname); if ($this->db->exec('PRAGMA encoding = "UTF-8";') === false) { $this->output->writeln($this->db->lastErrorCode() . " : " . $this->db->lastErrorMsg()); throw new \Exception("cannot set encoding UTF-8"); } }
/** * Returns the error string. * * @return string */ public function error() { if (0 === $this->conn->lastErrorCode()) { return ''; } return $this->conn->lastErrorMsg(); }
/** * @param string $databaseFilename */ public function __construct($databaseFilename, $tableName = 'events') { $databaseFilename = strval($databaseFilename); $tableName = strval($tableName); $this->_tableName = $tableName; $this->_databaseHandle = new SQLite3($databaseFilename); if ($this->_databaseHandle->lastErrorCode() != 0) { throw new Exception('Unable to connect to DB.'); } $this->_databaseHandle->exec(<<<EOT CREATE TABLE IF NOT EXISTS {$tableName} ( id INTEGER PRIMARY KEY, headers STRING, body STRING ) EOT ); }
function execute($query) { if (!$this->isConnected()) { throw new NotConnectedException(); } Connection::startMeasuring($this); if (func_num_args() > 1) { $query = call_user_func_array('sprintf', func_get_args()); } $result = $this->connection->query($query); Connection::endMeasuring($this); if (!$result) { throw new QueryException($this->connection->lastErrorMsg(), $this->connection->lastErrorCode()); } if ($result instanceof \SQLite3Result) { return new RecordSet($result); } return $result; }
/** * Test if a error exist, if yes than throw error * * @throws CHOQ_Exception * @param string $query */ public function testError($query = null) { if ($this->sqlite->lastErrorCode()) { $error = $this->sqlite->lastErrorMsg(); if ($query) { $error .= "\nSQL Query: {$query}"; } error($error); } }
/** * Checks the last error code and decide if and what kind of exception to throw. * @return true if nothing is wrong * @throws CoreXEngine\Cache\AccessException if we want to write a read-only file * @throws CoreXEngine\Cache\Exception for no special typed problem */ protected function checkError() { switch ($code = $this->database->lastErrorCode()) { case 8: throw new AccessException($this->database->lastErrorMsg(), $this->database->lastErrorCode()); break; default: if (0 < $code) { throw new Exception($this->database->lastErrorMsg(), $this->database->lastErrorCode()); } } return true; }
public function create_table_if_not_exist($tablename, $fieldsdefinition) { // check if tablename is already present $check = @parent::querySingle("SELECT count(*) FROM {$tablename}"); $code = @parent::lastErrorCode(); if (0 < $check || 0 == $check && 0 == $code) { return true; } else { $sql = "CREATE TABLE {$tablename} ({$fieldsdefinition})"; $res = $this->exec($sql); return $res !== false ? true : false; } }
/** * Execute the SQL query. * * @param string $sql * @throws Exception * @return void */ public function query($sql) { if ($this->isPdo) { $sth = $this->sqlite->prepare($sql); if (!$sth->execute()) { throw new Exception($sth->errorCode() . ': ' . $sth->errorInfo()); } else { $this->result = $sth; } } else { if (!($this->result = $this->sqlite->query($sql))) { throw new Exception('Error: ' . $this->sqlite->lastErrorCode() . ': ' . $this->sqlite->lastErrorMsg() . '.'); } } }
/** * Wykonanie zapytania bazy danych * * @param string $query * @return \SQLite3Result * @throws Exception */ public function execute($query) { if (!$this->connected) { $this->connect(); } if ($this->dbHandle == null) { return false; } $this->queryCount += 1; $tResult = $this->dbHandle->query($query); if (!$tResult) { throw new Exception($this->dbHandle->lastErrorMsg(), $this->dbHandle->lastErrorCode()); } /** * logowanie zapytań do pliku */ if ($this->writeToFile) { $this->writeLog($query); } return $tResult; }
/** * @param int $id * @param array $data * @param callable $callback * * @throws \Exception */ public function import(&$id, array $data, callable $callback) { foreach ($data as $uid => $elem) { $valuesFullText = $this->valuesFullText($elem); $valuesFilter = $this->valuesFilter($elem); if (sizeof($valuesFullText) > 0) { $json = json_encode($elem); $num = 1; $this->stmtInsertFilter->bindValue($num++, $id, SQLITE3_INTEGER); if ($this->useuid) { $this->stmtInsertFilter->bindValue($num++, $uid, SQLITE3_TEXT); } $this->stmtInsertFilter->bindValue($num++, $json, SQLITE3_TEXT); foreach ($valuesFilter as $valueFilter) { $this->stmtInsertFilter->bindValue($num++, $valueFilter); } if (@$this->stmtInsertFilter->execute() === false) { $lasterror = $this->db->lastErrorCode(); if ($lasterror != self::SQLITE_ERROR_CODE_CONSTRAINT) { $this->output->writeln($lasterror . " : " . $this->db->lastErrorMsg()); throw new \Exception("cannot insert filter fields"); } else { @$this->stmtInsertFilter->reset(); continue; } } $num = 1; $this->stmtInsertFullText->bindValue($num++, $id, SQLITE3_INTEGER); foreach ($valuesFullText as $valueFullText) { $this->stmtInsertFullText->bindValue($num++, $valueFullText, SQLITE3_TEXT); } if ($this->stmtInsertFullText->execute() === false) { $this->output->writeln($this->db->lastErrorCode() . " : " . $this->db->lastErrorMsg()); throw new \Exception("cannot insert full text fields"); } $id++; } $callback(); } }
public function errorCode() { return $this->handler->lastErrorCode(); }
/** * function to establish a database connection * * @return bool * @throws \RuntimeException if something went wrong establishing the connection */ public function open() { $conn = new \SQLite3($this->path, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, $this->password); if ($conn->lastErrorCode()) { throw new \RuntimeException('Failed to connect: #' . $conn->lastErrorCode() . ' | ' . $conn->lastErrorMsg()); } $this->conn = $conn; $this->status = 'open'; return true; }
/** * @param $input * @return SQLite3Result */ function save($input) { $db = new SQLite3('vorkurs.db'); $group = ''; if ($input['cs'] === true && $input['math'] === true) { $group = 'morning'; } else { if ($input['math'] === true) { $stmtCount = $db->prepare('SELECT count(*) FROM vorkurs WHERE math = 1 AND mathgroup = :group'); $stmtCount->bindValue(':group', 'afternoon'); $result = $stmtCount->execute()->fetchArray(); $countAfternoon = $result[0]; $stmtCount->clear(); $stmtCount->bindValue(':group', 'morning'); $result = $stmtCount->execute()->fetchArray(); $countMorning = $result[0]; $group = 'afternoon'; if ($countAfternoon > $countMorning + 10) { $group = 'morning'; } } } $stmt = $db->prepare('INSERT INTO vorkurs VALUES (:email, :lastname, :firstname, :math, :cs, :mathgroup, :laptop, :proglang, :os, :school)'); $stmt->bindValue(':lastname', $input['firstname'], SQLITE3_TEXT); $stmt->bindValue(':firstname', $input['lastname'], SQLITE3_TEXT); $stmt->bindValue(':email', $input['email'], SQLITE3_TEXT); $stmt->bindValue(':math', $input['math'] === true ? 1 : 0, SQLITE3_INTEGER); $stmt->bindValue(':cs', $input['cs'] === true ? 1 : 0, SQLITE3_INTEGER); $stmt->bindValue(':mathgroup', $group, SQLITE3_TEXT); $stmt->bindValue(':laptop', $input['laptop'], SQLITE3_TEXT); $stmt->bindValue(':proglang', $input['proglang'], SQLITE3_TEXT); $stmt->bindValue(':os', $input['os'], SQLITE3_TEXT); $stmt->bindValue(':school', $input['school'], SQLITE3_TEXT); $ret = $stmt->execute(); $data = array(); if ($ret !== false) { $mail = new PHPMailer(); $mail->CharSet = 'utf-8'; $mail->setLanguage('de'); //$mail->isSMTP(); $mail->From = '*****@*****.**'; $mail->FromName = 'Stephan Mielke'; $mail->addAddress($input['email']); // Add a recipient if ($group === 'morning') { $mail->addAttachment('pdf/Brief-NM-2015.pdf'); } if ($group === 'afternoon') { $mail->addAttachment('pdf/Brief-VM-2015.pdf'); } if ($input['cs'] === true) { $mail->addAttachment('pdf/Einladung-VK-Info.pdf'); } $mail->isHTML(true); $mail->Subject = 'Bestätigung der Anmeldung für den Vorkurs'; $mail->Body = 'Mit dieser Email erhalten Sie im Anhang alle wichtigen Informationen zum Vorkurs.'; $mail->AltBody = 'Mit dieser Email erhalten Sie im Anhang alle wichtigen Informationen zum Vorkurs.'; $data['cs'] = $input['cs']; $data['math'] = $input['math']; $data['group'] = $group; if (!$mail->send()) { $data['mailError'] = $mail->ErrorInfo; } } else { $data['dbError'] = $db->lastErrorCode(); } echo json_encode($data); return $ret; }
} $queriesCreate = array('dropexpected' => 'DROP TABLE IF exists expectedfail', 'expectedfail' => 'CREATE TABLE IF NOT EXISTS expectedfail ( `id` integer PRIMARY KEY AUTOINCREMENT, `id_report` bigint(20) NOT NULL, `test_name` varchar(128) NOT NULL )', 'success' => 'CREATE TABLE IF NOT EXISTS success ( `id` integer PRIMARY KEY AUTOINCREMENT, `id_report` bigint(20) NOT NULL, `test_name` varchar(128) NOT NULL )'); header('Content-Type: text/plain'); $d = dir('db'); while (false !== ($entry = $d->read())) { if (substr($entry, -6) == 'sqlite') { printf("%-20s ", $entry); $dbi = new SQLite3('db/' . $entry, SQLITE3_OPEN_READWRITE) or exit('cannot open DB to record results'); foreach ($queriesCreate as $table => $query) { $dbi->exec($query); if ($dbi->lastErrorCode() != '') { echo $dbi->lastErrorMsg(); } } // patch add field success @$dbi->exec('ALTER TABLE reports ADD COLUMN success unsigned int(10) NOT NULL default 0'); echo $dbi->lastErrorMsg(); $dbi->close(); echo "\n"; } } $d->close(); touch('db/update_20120407.lock');
if ($q) { while ($tab = $q->fetchArray(SQLITE3_ASSOC)) { $failedTestsArray[] = $tab; } } } $query = 'SELECT failed.test_name,COUNT(failed.id) as cpt,COUNT(DISTINCT failed.diff) as variations, datetime(reports.date) as date,success.id as success, r2.id as failedci FROM failed, reports LEFT JOIN success ON success.test_name=failed.test_name LEFT JOIN failed f2 ON (f2.test_name=failed.test_name AND f2.output = "") LEFT JOIN reports r2 ON (f2.id_report = r2.id AND r2.user_email="ciqa") WHERE failed.id_report = reports.id GROUP BY failed.test_name ORDER BY cpt DESC LIMIT ' . $limit; $q = @$database->query($query); if (!$q) { die("Error querying DB (error " . $database->lastErrorCode() . "): " . $database->lastErrorMsg()); } while ($tab = $q->fetchArray(SQLITE3_ASSOC)) { $failedTestsArray[] = $tab; } $database->close(); } else { if (!isset($_GET['summary_filter'])) { $filter = QA_REPORT_FILTER_ALL; } else { $filter = $_GET['summary_filter']; } $reportsPerVersion = get_summary_data($filter); $TITLE = "PHP Test Reports Summary"; } common_header();
public static function Log($level, $class, $message, $details = '', $object = '') { // Logging is disabled if database is set to false if (isset($GLOBALS['config']['path']['journal']) && $GLOBALS['config']['path']['journal'] === false) { return; } // Otherwise, database must exist if (!isset($GLOBALS['config']['path']['journal']) || empty($GLOBALS['config']['path']['journal'])) { throw new Exception('No journal database specified'); } if (!file_exists($GLOBALS['config']['path']['journal'])) { throw new Exception('Journal database not found'); } // Init database $conn = new SQLite3($GLOBALS['config']['path']['journal']); // Init values $values = array(); $values['level'] = "'" . $conn->escapeString($level) . "'"; $values['class'] = "'" . $conn->escapeString($class) . "'"; if (isset($GLOBALS['config']['object']['session'])) { $values['userid'] = $GLOBALS['config']['object']['session']->GetUserID(); } else { $values['userid'] = 0; } if (isset($_SERVER['REMOTE_ADDR'])) { $values['userip'] = "'" . $conn->escapeString($_SERVER['REMOTE_ADDR']) . "'"; } else { $values['userip'] = "''"; } $values['message'] = "'" . $conn->escapeString($message) . "'"; $values['details'] = "'" . $conn->escapeString(substr((string) $details, 0, 1024)) . "'"; if (isset($_SERVER['REQUEST_URI'])) { $values['request'] = "'" . $conn->escapeString($_SERVER['REQUEST_URI']) . "'"; } else { $values['request'] = "''"; } if (isset($_SERVER['SCRIPT_NAME'])) { $values['script'] = "'" . $conn->escapeString($_SERVER['SCRIPT_NAME']) . "'"; } elseif (isset($_SERVER['PHP_SELF'])) { $values['script'] = "'" . $conn->escapeString($_SERVER['PHP_SELF']) . "'"; } else { $values['script'] = "''"; } if (is_array($object)) { $values['object'] = "'" . $conn->escapeString(implode(',', $object)) . "'"; } else { $values['object'] = "'" . $conn->escapeString($object) . "'"; } // Check repeats $query = 'SELECT id FROM journal WHERE '; $where = ''; foreach ($values as $field => $value) { if (!empty($where)) { $where .= ' AND '; } $where .= '(' . $field . ' = ' . $value . ')'; } $where .= ' AND (date_added > ' . (time() - self::REPEAT_TIMEOUT) . ')'; $rs = $conn->query($query . $where); $row = $rs->fetchArray(); if ($row !== false) { // Increase repeat counter $query = 'UPDATE journal '; $query .= 'SET repeats = repeats + 1,date_repeat = ' . time() . ' '; $query .= 'WHERE id = ' . $row['id']; } else { // Insert journal entry $values['id'] = 'NULL'; $values['date_added'] = time(); $fields = implode('`,`', array_keys($values)); $data = implode(',', array_values($values)); $query = 'INSERT INTO journal (`' . $fields . '`) VALUES(' . $data . ')'; } // SQLite does not always honor its own busy timeout handler // So, if we get busy error we simply try again until we succeed or timeout ourselves $start = time(); $retry = true; $tries = 1; while ($retry) { try { $conn->exec($query); $retry = false; } catch (Exception $e) { // If busy then ignore it until timeout has lapsed. If not, throw exception again. if ($conn->lastErrorCode() != self::SQLITE_BUSY) { throw $e; } if (time() - $start > self::TIMEOUT) { throw new DatabaseException('Unable to write to database; still locked after waiting ' . self::TIMEOUT . ' seconds', $conn->lastErrorCode(), $query); } usleep(10000 * $tries); // 10ms times number of tries $tries++; } } }
<?php $db = new SQLite3(':memory:'); echo "SELECTING from invalid table\n"; $result = $db->query("SELECT * FROM non_existent_table"); echo "Closing database\n"; var_dump($db->close()); echo "Done\n"; // Trigger the use-after-free echo "Error Code: " . $db->lastErrorCode() . "\n"; echo "Error Msg: " . $db->lastErrorMsg() . "\n";
<?php $db = new SQLite3(':memory:'); var_dump($db->lastErrorCode('invalid argument')); echo "Done\n";
public function return_last_error() { return SQLite3::lastErrorCode(); }
/** * Insert PHP make test results in SQLite database * * The following structure must be used as first array : * [status] => enum(failed, success) * [version] => string - example: 5.4.1-dev * [userEmail] => mangled * [date] => unix timestamp * [phpinfo] => string - phpinfo() output (CLI) * [buildEnvironment] => build environment * [failedTest] => array: list of failed test. Example: array('/Zend/tests/declare_001.phpt') * [expectedFailedTest] => array of expected failed test (same format as failedTest) * [succeededTest] => array of successfull tests. Provided only when parsing ci.qa results (for now) * [tests] => array testName => array ( 'output' => string("Current output of test") 'diff' => string("Diff with expected output of this test") * @param array array to insert * @param array releases we accept (so that we don't accept a report that claims to be PHP 8.1 for example) * @return boolean success or not (for the moment, error leads to a call to 'exit;' ... not good I know) */ function insertToDb_phpmaketest($array, $QA_RELEASES = array()) { if (!is_array($array)) { // impossible to fetch data. We'll record this error later ... } else { if (strtolower($array['status']) == 'failed') { $array['status'] = 0; } elseif (strtolower($array['status']) == 'success') { $array['status'] = 1; } else { die('status unknown: ' . $array['status']); } if (!is_valid_php_version($array['version'], $QA_RELEASES)) { exit('invalid version'); } $dbFile = dirname(__FILE__) . '/db/' . $array['version'] . '.sqlite'; $queriesCreate = array('failed' => 'CREATE TABLE IF NOT EXISTS failed ( `id` integer PRIMARY KEY AUTOINCREMENT, `id_report` bigint(20) NOT NULL, `test_name` varchar(128) NOT NULL, `output` STRING NOT NULL, `diff` STRING NOT NULL, `signature` binary(16) NOT NULL )', 'expectedfail' => 'CREATE TABLE IF NOT EXISTS expectedfail ( `id` integer PRIMARY KEY AUTOINCREMENT, `id_report` bigint(20) NOT NULL, `test_name` varchar(128) NOT NULL )', 'success' => 'CREATE TABLE IF NOT EXISTS success ( `id` integer PRIMARY KEY AUTOINCREMENT, `id_report` bigint(20) NOT NULL, `test_name` varchar(128) NOT NULL )', 'reports' => 'CREATE TABLE IF NOT EXISTS reports ( id integer primary key AUTOINCREMENT, date datetime NOT NULL, status smallint(1) not null, nb_failed unsigned int(10) NOT NULL, nb_expected_fail unsigned int(10) NOT NULL, success unsigned int(10) NOT NULL, build_env STRING NOT NULL, phpinfo STRING NOT NULL, user_email varchar(64) default null )'); if (!file_exists($dbFile)) { //Create DB $dbi = new SQLite3($dbFile, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE); foreach ($queriesCreate as $table => $query) { $dbi->exec($query); if ($dbi->lastErrorCode() != '') { echo "ERROR when creating table " . $table . ": " . $dbi->lastErrorMsg() . "\n"; exit; } } $dbi->close(); } $dbi = new SQLite3($dbFile, SQLITE3_OPEN_READWRITE) or exit('cannot open DB to record results'); // handle tests with no success if (!isset($array['succeededTest'])) { $array['succeededTest'] = array(); } $query = "INSERT INTO `reports` (`id`, `date`, `status`, \n `nb_failed`, `nb_expected_fail`, `success`, `build_env`, `phpinfo`, user_email) VALUES (null, \n datetime(" . (int) $array['date'] . ", 'unixepoch', 'localtime'), \n " . (int) $array['status'] . ", \n " . count($array['failedTest']) . ", \n " . count($array['expectedFailedTest']) . ", \n " . count($array['succeededTest']) . ", \n ('" . $dbi->escapeString($array['buildEnvironment']) . "'), \n ('" . $dbi->escapeString($array['phpinfo']) . "'),\n " . (!$array['userEmail'] ? "NULL" : "'" . $dbi->escapeString($array['userEmail']) . "'") . "\n )"; $dbi->query($query); if ($dbi->lastErrorCode() != '') { echo "ERROR: " . $dbi->lastErrorMsg() . "\n"; exit; } $reportId = $dbi->lastInsertRowID(); foreach ($array['failedTest'] as $name) { if (substr($name, 0, 1) != '/') { $name = '/' . $name; } $test = $array['tests'][$name]; $query = "INSERT INTO `failed` \n (`id`, `id_report`, `test_name`, signature, `output`, `diff`) VALUES (null, \n '" . $reportId . "', '" . $name . "', \n X'" . md5($name . '__' . $test['diff']) . "',\n ('" . $dbi->escapeString($test['output']) . "'), ('" . $dbi->escapeString($test['diff']) . "'))"; @$dbi->query($query); if ($dbi->lastErrorCode() != '') { echo "ERROR when inserting failed test : " . $dbi->lastErrorMsg() . "\n"; exit; } } foreach ($array['expectedFailedTest'] as $name) { $query = "INSERT INTO `expectedfail` \n (`id`, `id_report`, `test_name`) VALUES (null, '" . $reportId . "', '" . $name . "')"; @$dbi->query($query); if ($dbi->lastErrorCode() != '') { echo "ERROR when inserting expected fail test : " . $dbi->lastErrorMsg() . "\n"; exit; } } foreach ($array['succeededTest'] as $name) { // sqlite files too big .. For the moment, keep only one success over time $res = $dbi->query('SELECT id, id_report FROM `success` WHERE test_name LIKE \'' . $dbi->escapeString($name) . '\''); if ($res->numColumns() > 0) { // hit ! do nothing atm } else { $query = "INSERT INTO `success` (`id`, `id_report`, `test_name`)\n VALUES (null, '" . $reportId . "', '" . $dbi->escapeString($name) . "')"; @$dbi->query($query); if ($dbi->lastErrorCode() != '') { echo "ERROR when inserting succeeded test : " . $dbi->lastErrorMsg() . "\n"; exit; } } } $dbi->close(); // remove cache if (file_exists($dbFile . '.cache')) { unlink($dbFile . '.cache'); } } return true; }
/** * return sql error array * @access private */ function sql_error() { return array('message' => $this->_connect_id ? $this->_connect_id->lastErrorMsg() : 'not-connected', 'code' => $this->_connect_id ? $this->_connect_id->lastErrorCode() : 'not-connected'); }
*/ if (!isset($_CONFIG["SECRET"]) || $_CONFIG["SECRET"] == "") { die("Please configure <b>inc/config.php</b>! You can use <i>inc/config.dist.php</i> as an example."); } /** * Try to enable errors */ if ($_CONFIG["SHOW_ERRORS"]) { ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(-1); } if (!isset($_DB)) { $_DB = new SQLite3($_CONFIG["DATABASE"]); } if ($_DB->lastErrorCode() != 0) { die("Fatal DB Error!"); } $ok = false; $msg = "keine"; $_USER = false; if (isset($_POST['user']) and isset($_POST['pass'])) { $user = $_POST['user']; $pass = $_POST['pass']; $q = $_DB->prepare("SELECT * FROM users WHERE Login = :1;"); $q->bindValue(":1", $user); $r = $q->execute(); if ($r && ($_USER = $r->fetchArray())) { $pw = explode(":", $_USER['Password']); $hash = $pw[0]; $stored = $pw[1];
/** * {@inheritdoc} */ public function errorCode() { return $this->_conn->lastErrorCode(); }