class SQLiteDatabase (View source)

Methods

__construct(string $filename, int $mode = 0666, string $error_message)

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0)

resource|false
query(string $query, int $result_type, string $error_message)

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0)

bool
queryExec(string $query, string $error_message)

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0)

array|false
arrayQuery(string $query, int $result_type, bool $decode_binary)

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0) Execute a query against a given database and returns an array

array
singleQuery(string $query, bool $first_row_only, bool $decode_binary)

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.1) Executes a query and returns either an array for one single column or the value of the first row

resource
unbufferedQuery(string $query, int $result_type = SQLITE_BOTH, string $error_message = null)

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0) Execute a query that does not prefetch and buffer all data

int
lastInsertRowid()

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0) Returns the rowid of the most recently inserted row

int
changes()

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0) Returns the number of rows that were changed by the most recent SQL statement

createAggregate(string $function_name, callable $step_func, callable $finalize_func, int $num_args = -1)

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0) Register an aggregating UDF for use in SQL statements

createFunction(string $function_name, callable $callback, int $num_args = -1)

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0) Registers a "regular" User Defined Function for use in SQL statements

int
busyTimeout(int $milliseconds)

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0) Set busy timeout duration, or disable busy handlers

int
lastError()

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0) Returns the error code of the last error for a database

array
fetchColumnTypes(string $table_name, int $result_type = SQLITE_ASSOC)

(PHP 5 < 5.4.0) Return an array of column types from a particular table

Details

final __construct(string $filename, int $mode = 0666, string $error_message)

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0)

Parameters

string $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.

int $mode

[optional]

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.

string $error_message

[optional]

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.

resource|false query(string $query, int $result_type, string $error_message)

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0)

Parameters

string $query

The query to be executed.

Data inside the query should be https://php.net/manual/en/function.sqlite-escape-string.php properly escaped.

int $result_type

[optional]

The optional result_type parameter accepts a constant and determines how the returned array will be indexed. Using SQLITE_ASSOC will return only associative indices (named fields) while SQLITE_NUM will return only numerical indices (ordinal field numbers). SQLITE_BOTH will return both associative and numerical indices. SQLITE_BOTH is the default for this function.

string $error_message

[optional]

The specified variable will be filled if an error occurs. This is specially important because SQL syntax errors can't be fetched using the {\sqlite_last_error()} function.

Return Value

resource|false

This function will return a result handle or FALSE on failure. For queries that return rows, the result handle can then be used with functions such as {\sqlite_fetch_array()} and {\sqlite_seek()}.

Regardless of the query type, this function will return FALSE if the query failed.

{\sqlite_query()} returns a buffered, seekable result handle. This is useful for reasonably small queries where you need to be able to randomly access the rows. Buffered result handles will allocate memory to hold the entire result and will not return until it has been fetched. If you only need sequential access to the data, it is recommended that you use the much higher performance {\sqlite_unbuffered_query()} instead.

bool queryExec(string $query, string $error_message)

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0)

Parameters

string $query

The query to be executed.

Data inside the query should be https://php.net/manual/en/function.sqlite-escape-string.php properly escaped.

string $error_message

[optional]

The specified variable will be filled if an error occurs. This is specially important because SQL syntax errors can't be fetched using the {\sqlite_last_error()} function.

Return Value

bool

This function will return a boolean result; TRUE for success or FALSE for failure. If you need to run a query that returns rows, see {\sqlite_query()}.

The column names returned by SQLITE_ASSOC and SQLITE_BOTH will be case-folded according to the value of the https://php.net/manual/en/sqlite.configuration.php#ini.sqlite.assoc-case sqlite.assoc_case configuration option.

array|false arrayQuery(string $query, int $result_type, bool $decode_binary)

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0) Execute a query against a given database and returns an array

Parameters

string $query

The query to be executed.

Data inside the query should be https://php.net/manual/en/function.sqlite-escape-string.php properly escaped.

int $result_type

[optional]

The optional result_type parameter accepts a constant and determines how the returned array will be indexed. Using SQLITE_ASSOC will return only associative indices (named fields) while SQLITE_NUM will return only numerical indices (ordinal field numbers). SQLITE_BOTH will return both associative and numerical indices. SQLITE_BOTH is the default for this function.

bool $decode_binary

[optional]

When the decode_binary parameter is set to TRUE (the default), PHP will decode the binary encoding it applied to the data if it was encoded using the {\sqlite_escape_string()}. You should normally leave this value at its default, unless you are interoperating with databases created by other sqlite capable applications.

Return Value

array|false

Returns an array of the entire result set; FALSE otherwise.

The column names returned by SQLITE_ASSOC and SQLITE_BOTH will be case-folded according to the value of the https://php.net/manual/en/sqlite.configuration.php#ini.sqlite.assoc-case sqlite.assoc_case configuration option.

array singleQuery(string $query, bool $first_row_only, bool $decode_binary)

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.1) Executes a query and returns either an array for one single column or the value of the first row

Parameters

string $query
bool $first_row_only [optional]
bool $decode_binary [optional]

Return Value

array

resource unbufferedQuery(string $query, int $result_type = SQLITE_BOTH, string $error_message = null)

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0) Execute a query that does not prefetch and buffer all data

Parameters

string $query

The query to be executed.

Data inside the query should be https://php.net/manual/en/function.sqlite-escape-string.php properly escaped.

int $result_type

[optional]

The optional result_type parameter accepts a constant and determines how the returned array will be indexed. Using SQLITE_ASSOC will return only associative indices (named fields) while SQLITE_NUM will return only numerical indices (ordinal field numbers). SQLITE_BOTH will return both associative and numerical indices. SQLITE_BOTH is the default for this function.

string $error_message [optional]

Return Value

resource

Returns a result handle or FALSE on failure. {\sqlite_unbuffered_query()} returns a sequential forward-only result set that can only be used to read each row, one after the other.

int lastInsertRowid()

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0) Returns the rowid of the most recently inserted row

Return Value

int

Returns the row id, as an integer.

int changes()

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0) Returns the number of rows that were changed by the most recent SQL statement

Return Value

int

Returns the number of changed rows.

createAggregate(string $function_name, callable $step_func, callable $finalize_func, int $num_args = -1)

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0) Register an aggregating UDF for use in SQL statements

Parameters

string $function_name

The name of the function used in SQL statements.

callable $step_func

Callback function called for each row of the result set. Function parameters are &$context, $value, ....

callable $finalize_func

Callback function to aggregate the "stepped" data from each row. Function parameter is &$context and the function should return the final result of aggregation.

int $num_args

[optional]

Hint to the SQLite parser if the callback function accepts a predetermined number of arguments.

createFunction(string $function_name, callable $callback, int $num_args = -1)

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0) Registers a "regular" User Defined Function for use in SQL statements

Parameters

string $function_name

The name of the function used in SQL statements.

callable $callback

Callback function to handle the defined SQL function.

Note: Callback functions should return a type understood by SQLite (i.e. https://php.net/manual/en/language.types.intro.php scalar type).

int $num_args

[optional]

Note: Two alternative syntaxes are supported for compatibility with other database extensions (such as MySQL). The preferred form is the first, where the dbhandle parameter is the first parameter to the function.

int busyTimeout(int $milliseconds)

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0) Set busy timeout duration, or disable busy handlers

Parameters

int $milliseconds

The number of milliseconds. When set to 0, busy handlers will be disabled and SQLite will return immediately with a SQLITE_BUSY status code if another process/thread has the database locked for an update. PHP sets the default busy timeout to be 60 seconds when the database is opened.

Return Value

int

Returns an error code, or 0 if no error occurred.

int lastError()

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0) Returns the error code of the last error for a database

Return Value

int

Returns an error code, or 0 if no error occurred.

array fetchColumnTypes(string $table_name, int $result_type = SQLITE_ASSOC)

(PHP 5 < 5.4.0) Return an array of column types from a particular table

Parameters

string $table_name

The table name to query.

int $result_type

[optional]

The optional result_type parameter accepts a constant and determines how the returned array will be indexed. Using SQLITE_ASSOC will return only associative indices (named fields) while SQLITE_NUM will return only numerical indices (ordinal field numbers). SQLITE_ASSOC is the default for this function.

Return Value

array

Returns an array of column data types; FALSE on error.

The column names returned by SQLITE_ASSOC and SQLITE_BOTH will be case-folded according to the value of the https://php.net/manual/en/sqlite.configuration.php#ini.sqlite.assoc-case sqlite.assoc_case configuration option.