function connect() { $this->_conn = @sqlite_factory($this->_db_path); if ($this->_conn === null) { throw new Exception("Unable to connect to database: " . sqlite_error_string($this->_conn->lastError())); } # if $this->createDatabase(); } # connect()
function connect() { $this->_conn = @sqlite_factory($this->_db_path); if ($this->_conn === null) { throw new Exception("Unable to connect to database: " . sqlite_error_string($this->_conn->lastError())); } # if # Create the database structure $dbStruct = new SpotStruct_sqlite($this); $dbStruct->createDatabase(); }
public function __construct($dsn) { $connect = 'sqlite_' . (isset($dsn['persist']) && $dsn['persist'] ? 'p' : '') . 'open'; if (!is_callable($connect)) { return $this->_setLastError("-1", "SQLite extension is not loaded", $connect); } $err = ''; try { $this->link = sqlite_factory($dsn['path'], 0666, $err); } catch (Exception $e) { $this->_setLastError($e->getCode(), $e->getMessage(), 'sqlite_factory'); } }
public function __construct($driver_config, $table_config) { $path = $driver_config['path']; $need_generate = !file_exists($path); $this->conn = sqlite_factory($path); $this->tblconf = $table_config; if ($need_generate) { $this->generate_table_meta(); foreach (array_keys($table_config) as $table) { $this->generate_table($table); } } }
/** Initialises a new sqlite database. This driver accepts the following parameters: * create: Whether to create the database file if it does not exist (defaults to false). * file: The filename of the SQLite database (mandatory). @param $aParams The parameters of the driver. @throw ConfigurationException The SQLite PHP extension is missing. @throw InvalidArgumentException Parameter "file" is missing. @throw FileNotFoundException The database file does not exist and the parameter "create" does not evaluate to true. @throw DatabaseException Failed to connect to the database. */ public function __construct($aParams = array()) { function_exists('sqlite_factory') or burn('ConfigurationException', sprintf(_WT('The "%s" PHP extension is required by this database driver.'), 'SQLite')); isset($aParams['file']) or burn('InvalidArgumentException', sprintf(_WT('Parameter "%s" is missing.'), 'file')); $aParams += array('create' => false); $aParams['create'] or file_exists($aParams['file']) or burn('FileNotFoundException', _WT('The database file does not exist and the parameter "create" does not evaluate to true.')); $oDb = sqlite_factory($aParams['file'], 0666, $sLastError); $oDb !== null or burn('DatabaseException', sprintf(_WT("Failed to connect to the database with the following error:\n%s"), $sLastError)); // By default SQLite 2 returns full column names when there's joins // For better interoperability with other DBMS we prefer short names $oDb->query('PRAGMA short_column_names = ON'); $this->oDb = $oDb; }
$query = $dbhandle->query('SELECT name, email FROM users LIMIT 25'); // buffered result set $query = $dbhandle->unbufferedQuery('SELECT name, email FROM users LIMIT 25'); // unbuffered result set while ($entry = $query->fetch(SQLITE_ASSOC)) { echo 'Name: ' . $entry['name'] . ' E-mail: ' . $entry['email']; } if ($db = sqlite_open('mysqlitedb', 0666, $sqliteerror)) { sqlite_query($db, 'CREATE TABLE foo (bar varchar(10))'); sqlite_query($db, "INSERT INTO foo VALUES ('fnord')"); $result = sqlite_query($db, 'select bar from foo'); var_dump(sqlite_fetch_array($result)); } else { die($sqliteerror); } $dbhandle = sqlite_factory('sqlitedb'); $dbhandle->query('SELECT user_id, username FROM users'); /* functionally equivalent to: */ $dbhandle = new SQLiteDatabase('sqlitedb'); $dbhandle->query('SELECT user_id, username FROM users'); function sqlite_data_seek($result, $numrow) { if ($numrow == 0) { return sql_rewind($result); } else { return sql_seek($result, $numrow); } } function md5_and_reverse($string) { return strrev(md5($string));