sqlite_open

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0)
Opens an SQLite database and create the database if it does not exist
resource sqlite_open ( string $filename [, int $mode = 0666 [, string &$error_message ]] )

Object oriented style (constructor):

final public SQLiteDatabase::__construct ( string $filename [, int $mode = 0666 [, string &$error_message ]] )

Opens an SQLite database or creates the database if it does not exist.

Parameters:
filename

The filename of the SQLite database. If the file does not exist, SQLite will attempt to create it. PHP must have write permissions to the file if data is inserted, the database schema is modified or to create the database if it does not exist.

mode

The mode of the file. Intended to be used to open the database in read-only mode. Presently, this parameter is ignored by the sqlite library. The default value for mode is the octal value 0666 and this is the recommended value.

error_message

Passed by reference and is set to hold a descriptive error message explaining why the database could not be opened if there was an error.

Returns:

Returns a resource (database handle) on success, FALSE on error.

Notes:
Starting with SQLite library version 2.8.2, you can specify :memory: as the filename to create a database that lives only in the memory of the computer. This is useful mostly for temporary processing, as the in-memory database will be destroyed when the process ends. It can also be useful when coupled with the ATTACH DATABASE SQL statement to load other databases and move and query data between them.
SQLite is safe mode and open_basedir aware.
Examples:
sqlite_open() example
<?php
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);
}
?>

See also:

sqlite_popen() -

sqlite_close() -

sqlite_factory() -

doc_php
2016-02-24 16:18:30
Comments
Leave a Comment

Please login to continue.