Function Reference


In this section, SQLite functions and their results are described and organized by function category. The function is given first, followed by its description.

Opening and Closing a Database

 resource sqlite_open ( string filename [, int mode [, string &error_message]]) 

Opens the database specified by filenameeither in the current directory or referenced via a relative or absolute pathand returns a database connection resource.

 resource sqlite_popen ( string filename [, int mode [, string &error_message]]) 

Opens a persistent connection to the specified database file. To open an in-memory database, use :memory: as the filename.

Note

When the sqlite_popen() function is run in a web environment, file permissions must allow the web server user to gain read and write access to both the database file itself and its directory so that journal files can be written.


 void sqlite_close ( resource dbhandle) 

Closes a database connection.

 void sqlite_busy_timeout ( resource dbhandle, int milliseconds) 

Specifies the duration in milliseconds for which SQLite should wait for a lock to clear on the database file before failing with an SQLITE_BUSY return code. The default value is 60 seconds (60,000 milliseconds).

Executing a Query

 resource sqlite_query ( resource dbhandle, string query) resource sqlite_query ( string query, resource dbhandle) 

Causes SQLite to execute the given query and returns a seekable result set resource.

Note

The arguments to sqlite_query() and other such functions can be specified in either order for consistency with both other SQLite interfaces and other PHP extensions. The preferred ordering is to specify the database resource firstthe order used by other SQLite extensions.


 resource sqlite_unbuffered_query ( resource dbhandle, string query) resource sqlite_unbuffered_query ( string query, resource dbhandle) 

Works similarly to sqlite_query() but returns a result resource that can only be accessed sequentially. Unless random access is required, this function should be used as it provides much better performance.

 string sqlite_escape_string ( string item) 

Returns a version of item that is safe for storage by SQLite, by doubling up single quotes and encoding characters that are not binary-safe.

Error Reporting

 int sqlite_last_error ( resource dbhandle) 

Returns the error code of the last operation performed on database resource dbhandle.

 string sqlite_error_string ( int error_code) 

Converts the return value from sqlite_last_error() into a human-readable error message string.

Finding Information About a Query

 int sqlite_last_insert_rowid ( resource dbhandle) 

Returns the most recently assigned autoincrementing value of an INTEGER PRIMARY KEY field in dbhandle.

 int sqlite_changes ( resource dbhandle) 

Returns the number of rows affected by the most recent UPDATE or DELETE operation on dbhandle.

 int sqlite_num_rows ( resource result) 

Returns the total number of rows returned in the result resource result.

 int sqlite_num_fields ( resource result) 

Returns the total number of fields in the query that produced result resource result.

 string sqlite_field_name ( resource result, int field_index) 

Returns the name of the field at position field_index in result. The leftmost field in the query has field index zero.

Processing a Result Set

 mixed sqlite_column ( resource result, mixed index_or_name                       [, bool decode_binary]) 

Returns the value of the column from result resource result at the current result handle pointer specified by either field index index or column name name.

 bool sqlite_next ( resource result) 

Advances the result handle pointer for result to the next row.

 bool sqlite_has_more ( resource result) 

Returns trUE if result has more rows still to be fetched. FALSE indicates that the result handle pointer is at the end of the result.

 array sqlite_fetch_array ( resource result                            [, int result_type [, bool decode_binary]]) 

Returns an array containing the next row of data from result and advances the result handle pointer. The types of key values for the array are determined by the optional result_type constant, discussed at the beginning of the chapter.

 array sqlite_current ( resource result                        [, int result_type [, bool decode_binary]]) 

Returns an array containing the current row of data from result. The result handle pointer is not changed.

 string sqlite_fetch_single ( resource result                              [, int result_type [, bool decode_binary]]) 

Returns an array containing only the first row of data from result. This is the most optimal way to process a result if only the first record returned is required.

Random Data Access Functions

A buffered, seekable result resource is required for these functions. They cannot be used if the result was returned by sqlite_unbuffered_query().

 bool sqlite_seek ( resource result, int rownum) 

Moves the result handle pointer for result to the row specified by rownum. Returns trUE on success or FALSE if rownum does not exist.

 bool sqlite_rewind ( resource result) 

Moves the result handle pointer to the very first row of result. Equivalent to using sqlite_seek() to row zero.

Convenience Functions

 array sqlite_array_query ( resource dbhandle, string query                           [, int result_type [, bool decode_binary]]) array sqlite_array_query ( string query, resource dbhandle                           [, int result_type [, bool decode_binary]]) 

Returns a single, two-dimensional array made up of associative arrays of values for each record in the dataset returned by query.

In $array[row][col], row is the row number beginning at zero and col is the field index number or name depending on the optional result_type setting.

Finding Information About SQLite

 string sqlite_libversion ( void ) 

Returns a string containing the version of the library linked with PHP.

 string sqlite_libencoding ( void ) 

Returns a string containing the encoding version of the linked library.

Custom Functions (UDF)

 bool sqlite_create_function ( resource dbhandle, string function_name,                               mixed callback [, int num_args]) 

Registers a user-defined SQL function called function_name that executes the PHP code in the function with the name given in the callback argument. The function is available only within the dbhandle resource.

 bool sqlite_create_aggregate ( resource dbhandle, string function_name,                                 mixed step_func, mixed finalize_func                                [, int num_args]) 

Registers a user-defined aggregating SQL function called function_name that executes step_func once for each row in the query, and finalize_func once after all rows have been returned.

 string sqlite_udf_encode_binary ( string data) string sqlite_udf_decode_binary ( string data) 

Encodes and decodes, respectively, binary data passed as parameters to a user-defined function. These functions impact performance and should only be used where a user-defined function is required to handle binary data.



    SQLite
    SQLite
    ISBN: 067232685X
    EAN: 2147483647
    Year: 2004
    Pages: 118
    Authors: Chris Newman

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net