Class db_SQLite

Description

SQLite class.

Located in /db_sqlite.class.php (line 20)


	
			
Class Constant Summary
Variable Summary
string $appname
string $currentQuery
string $database
integer $db_mode
integer $debug
string $myErrStr
integer $showError
resource $sock
Method Summary
static float GetMicrotime ()
db_SQLite __construct ([string $ext_config = ''])
integer AffectedRows ([resource $sock = -1])
void Commit ()
mixed Connect ([string $database = ''], [string $mode = 0])
void Disconnect ([mixed $other_sock = -1])
string EscapeString (string $str)
array FetchResult (mixed $result, [integer $resflag = SQLITE_ASSOC])
void FreeResult (mixed $result)
string GetClassVersion ()
integer GetDebug ()
integer GetErrno ([mixed $other_sock = -1])
integer GetErrorHandling ()
string GetErrorText ([mixed $other_sock = -1])
integer GetQueryCount ()
float GetQueryTime ()
integer LastInsertId ([mixed $extsock = -1])
void NumRows ( $result, resource $stmt)
void PrintDebug (string $msg)
void Print_Error ([string $ustr = ""], [mixed $var2dump = ""])
mixed Query (string $querystring, [integer $resflag = SQLITE_ASSOC], [integer $no_exit = 0])
mixed QueryResult (string $querystring, [integer $no_exit = 0])
void Rollback ()
void SetDebug (integer $state)
void SetErrorHandling (integer $val)
string Version ()
Variables
string $appname = '' (line 55)

The Name of the application using this class.

  • access: protected
string $currentQuery = '' (line 62)

Contains the actual query to be processed.

  • access: protected
string $database = '' (line 41)

The Database filename.

  • access: protected
integer $db_mode = 0666 (line 48)

The default database filename permission mode.

  • access: protected
integer $debug = db_SQLite::DBOF_DEBUGOFF (line 76)

Debugstate, default is OFF.

  • access: protected
string $myErrStr = '' (line 104)

Error string of last sqlite operation (set in Print_Error()).

  • private:
integer $showError = db_SQLite::DBOF_SHOW_NO_ERRORS (line 69)

Flag indicates how the class should interact with errors

  • access: protected
resource $sock = NULL (line 34)

Internal connection handle.

  • access: protected
Methods
static method GetMicrotime (line 872)

Returns microtime in format s.mmmmm.

Used to measure SQL execution time.

  • return: the current time in microseconds.
  • access: public
static float GetMicrotime ()
Constructor __construct (line 160)

Constructor of class.

  • access: public
db_SQLite __construct ([string $ext_config = ''])
  • string $ext_config: Pass here the full name to your define file where all external class defines are set. If empty uses "dbdefs.inc.php".
AffectedRows (line 421)

Returns number of rows affected by most recent DML operation against $dbhandle.

integer AffectedRows ([resource $sock = -1])
  • resource $sock: Optional a connection handle, if none given the internal socket will be used.
Commit (line 471)

Commits current transaction.

Note: Requires BEGIN TRANSACTION first! Without BEGIN TRANSACTION an auto-transaction is always auto-commited!

void Commit ()
Connect (line 210)

Performs the connection to a SQLite database file.

If anything goes wrong calls Print_Error(). You should set the defaults for your connection by setting database filename in dbdefs.inc.php and leave connect() parameters empty.

mixed Connect ([string $database = ''], [string $mode = 0])
  • string $database: Optional Filename of database to use
  • string $mode: Optional the file protection bits as octal number, defaults to 0666.
Disconnect (line 256)

Disconnects from SQLite database.

You may optionally pass an external link identifier.

void Disconnect ([mixed $other_sock = -1])
  • mixed $other_sock: Optionally your own connection handle to close, else internal will be used
EscapeString (line 838)

Escapes a given string with the 'sqlite_escape_string' method.

Always use this function to avoid SQL injections when adding dynamic data to SQLite! This function also handles the settings for magic_quotes_gpc, if this setting is enabled it will call stripslashes() first.

  • return: The escaped string.
  • access: public
string EscapeString (string $str)
  • string $str: The string to escape.
FetchResult (line 390)

Fetches next row from result handle.

Returns either numeric array (SQL_NUM), associative array (SQL_ASSOC) or both (SQLITE_BOTH) for one data row as pointed to by result var.

array FetchResult (mixed $result, [integer $resflag = SQLITE_ASSOC])
  • mixed $result: The resource identifier as returned by QueryResult()
  • integer $resflag: How you want the data to be returned:
    • SQLITE_ASSOC = Data is returned as associative array.
    • SQLITE_NUM = Data is returned as numbered array.
    • SQLITE_BOTH = Data is returned both as associative and numbered array.
FreeResult (line 409)

Frees result returned by QueryResult().

Note that SQLite has nothing to free (?) so here only the internal query variable is set to an empty string.

void FreeResult (mixed $result)
  • mixed $result: The resource identifier you want to be freed.
GetClassVersion (line 816)

Returns version of this class.

  • return: The version of this class.
  • access: public
string GetClassVersion ()
GetDebug (line 538)

Returns the current debug setting.

integer GetDebug ()
GetErrno (line 579)

Retrieve last SQLite error number.

  • return: The SQLite error number of the last operation
  • see: sqlite_last_error
  • access: public
integer GetErrno ([mixed $other_sock = -1])
  • mixed $other_sock: Optionally your own connection handle to check, else internal will be used
GetErrorHandling (line 513)

Returns the current error handling mode.

integer GetErrorHandling ()
GetErrorText (line 611)

Retrieve last SQLite error description.

  • return: The SQLite error description of the last operation
  • see: mysql_error
  • access: public
string GetErrorText ([mixed $other_sock = -1])
  • mixed $other_sock: Optionally your own connection handle to check, else internal will be used
GetQueryCount (line 852)

Returns amount of queries executed by this class.

  • return: Querycount
  • access: public
integer GetQueryCount ()
GetQueryTime (line 861)

Returns amount of time spend on queries executed by this class.

  • return: Time in seconds.msecs spent in executin MySQL code.
  • access: public
float GetQueryTime ()
LastInsertId (line 454)

Returns last used auto_increment id.

integer LastInsertId ([mixed $extsock = -1])
  • mixed $extsock: Optionally an external SQLite socket to use. If not given the internal socket is used.
NumRows (line 443)

Returns number of rows in a result set.

Note: This only works for statements returning a result set, for DML operations use AffectedRows() !

void NumRows ( $result, resource $stmt)
  • resource $stmt: The resource as returned from QueryResult()
  • $result
PrintDebug (line 549)

Handles output according to internal debug flag.

void PrintDebug (string $msg)
  • string $msg: The Text to be included in the debug message.
Print_Error (line 646)

Prints out SQLite Error in own <div> container and exits.

Please note that this function does not return as long as you have not set DBOF_RETURN_ALL_ERRORS!

void Print_Error ([string $ustr = ""], [mixed $var2dump = ""])
  • string $ustr: User-defined Error string to show
  • mixed $var2dump: Optionally a variable to print out with print_r()
Query (line 290)

Single-Row query method.

Returns only the first row of a given query! Resflag can be one of SQLITE_NUM or SQLITE_ASSOC or SQLITE_BOTH depending on what kind of array you want to be returned.

mixed Query (string $querystring, [integer $resflag = SQLITE_ASSOC], [integer $no_exit = 0])
  • string $querystring: The query to be executed.
  • integer $resflag: Decides how the result should be returned:
    • SQLITE_ASSOC = Data is returned as associative array (default value).
    • SQLITE_NUM = Data is returned as numbered array.
    • SQLITE_BOTH = Data is returned both as numbered and as associative array.
  • integer $no_exit: Decides how the class should react on errors. If you set this to 1 the class won't automatically exit on an error but instead return the sqlite_errno value. Default of 0 means that the class calls Print_Error() and exists.
QueryResult (line 345)

Performs a multi-row query and returns result identifier.

  • return: A resource identifier or an errorcode (if $no_exit = 1)
  • see: sqlite_query()
  • access: public
mixed QueryResult (string $querystring, [integer $no_exit = 0])
  • string $querystring: The Query to be executed
  • integer $no_exit: The error indicator flag, can be one of:
    • 0 = (Default), In case of an error Print_Error is called and script terminates
    • 1 = In case of an error this function returns the error from sqlite_last_error()
Rollback (line 485)

Rollback current transaction.

Note: Requires BEGIN TRANSACTION first! Without BEGIN TRANSACTION an auto-transaction is always auto-commited!

void Rollback ()
SetDebug (line 528)

Function allows debugging of SQL Queries.

$state can have these values:

  • db_SQLite::DBOF_DEBUGOFF = Turn off debugging
  • db_SQLite::DBOF_DEBUGSCREEN = Turn on debugging on screen (every Query will be dumped on screen)
  • db_SQLite::DBOF_DEBUFILE = Turn on debugging on PHP errorlog
You can mix the debug levels by adding the according defines!

void SetDebug (integer $state)
  • integer $state: The DEBUG Level you want to be set
SetErrorHandling (line 502)

Allows to set the handling of errors.

  • db_SQLite::DBOF_SHOW_NO_ERRORS => Show no security-relevant informations
  • db_SQLite::DBOF_SHOW_ALL_ERRORS => Show all errors (useful for develop)
  • db_SQLite::DBOF_RETURN_ALL_ERRORS => No error/autoexit, just return the mysql_error code.

  • access: public
void SetErrorHandling (integer $val)
  • integer $val: The Error Handling mode you wish to use.
Version (line 825)

Returns SQLite library version.

  • return: SQLite library version.
  • access: public
string Version ()
Class Constants
DBOF_DEBUGFILE = 4 (line 132)

DEBUG: Debug to error.log

DBOF_DEBUGOFF = 1 (line 128)

DEBUG: No Debug Info

DBOF_DEBUGSCREEN = 2 (line 130)

DEBUG: Debug to screen

DBOF_RETURN_ALL_ERRORS = 2 (line 143)

Connect and error handling.

If NO_ERRORS is set and an error occures, the class still reports an an error of course but the error shown is reduced to avoid showing sensible informations in a productive environment. Set RETURN_ALL_ERRORS if you want to handle errors yourself.

DBOF_SHOW_ALL_ERRORS = 1 (line 142)

Connect and error handling.

If NO_ERRORS is set and an error occures, the class still reports an an error of course but the error shown is reduced to avoid showing sensible informations in a productive environment. Set RETURN_ALL_ERRORS if you want to handle errors yourself.

DBOF_SHOW_NO_ERRORS = 0 (line 141)

Connect and error handling.

If NO_ERRORS is set and an error occures, the class still reports an an error of course but the error shown is reduced to avoid showing sensible informations in a productive environment. Set RETURN_ALL_ERRORS if you want to handle errors yourself.

SQLITEDB_ERR_EXTENSION_MISSING = -5 (line 153)

All defines for custom error codes *

SQLITEDB_ERR_NO_ACTIVE_CONNECT = -3 (line 151)

All defines for custom error codes *

SQLITEDB_ERR_NO_APPNAME_DEFINE = -1 (line 149)

All defines for custom error codes *

SQLITEDB_ERR_NO_CONNECTION = -2 (line 150)

All defines for custom error codes *

SQLITEDB_ERR_SQL_SYNTAX_ERROR = -4 (line 152)

All defines for custom error codes *

Documentation generated on Sat, 07 Aug 2010 20:01:01 +0200 by phpDocumentor 1.4.3