UNB Components Code Reference

UnbDatabase class

The database connection class provides basic query abstraction support and methods to easily execute SQL statements and query record sets, records or single values with an SQL query.

It establishes the connection to the database provider with PHP Data Objects (PDO) which technically allows using diverse database backends. Still the submitted queries must be formulated such that each DBMS to be used understands them.

UnbDatabase is a singleton class, there can only be one single instance of it during runtime. This way, the database connection can be used from multiple classes without passing its reference everywhere.

Public methods

   AddKeylistKey

Adds a new key to a key list.

S AsBool

Interprets a mixed value returned from the database as boolean.

   Close

Closes the database connection.

   Commit

Commits a transaction.

S ConvertDateTime

Converts a date/time value between PHP's UNIX timestamps and the SQL notation.

S EscapeLikeWildcards

Escape a value to use the wildcards * and ? instead of SQL's % and _.

   Execute

Executes an SQL statement that returns no data.

   GetDriverName

Gets the driver name used for the database connection.

   GetErrorMessage

Gets the message of the last occured database error.

S GetInstance

Gets the instance of this class.

   GetKeylistKeys

Gets all keys in a key list referenced by an entity.

   GetLastAutoValue

Gets the auto value generated by the last query.

S GetNewInstance

Gets a separate instance of this class.

   GetRowsAffected

Gets the number of rows affected by the last SQL statement (only for DELETE, INSERT and UPDATE).

   GetStatistics

Gets statistic data.

   IsConstraintError

Gets a value indicating whether the last error condition describes a constraint violation.

   IsOpen

Gets a value indicating whether the database connection is open.

   Open

Opens a database connection.

   Optimise

Optimises the database.

   Prepare

Prepares an SQL statement.

   Query

Executes an SQL statement and returns all records.

   QueryArray

Executes an SQL statement and returns the first column of all records.

   QueryRecord

Executes an SQL statement and returns the first record.

   QueryValue

Executes an SQL statement and returns a single value.

   RemoveKeylistKey

Removes a key from a key list.

   ResetKeylistKeys

Removes all keys from a key list and set new keys.

   RollBack

Rolls back a transaction.

S SQLite_ExtractValue

SQLite UDF (user defined function) for XML access.

   StartTransaction

Starts a new transaction.

Private methods

   Class constructor

Private constructor, does nothing but preventing an unwanted instantiation of this class.

   DetermineErrorCondition

Finds out what the problem was. :-)

   FetchLastAutoValue

Fetches the last inserted auto increment value from the database connection and stores it for later retrieval with GetLastAutoValue.

   GetSequenceValue

Gets the next value of a sequence.

   InternalExecute

Actually executes an SQL query.

   ProcessSql

Basic SQL query processing.

   ResetLastAutoValue

Resets the last auto value.

   ShowQueryInfo

Shows query information and errors.

Private fields

busyError  –  default: false

Indicates whether the last query ran against a lock and should be repeated (SQLite only)

connectData  –  default: null

Array with information on how to connect to the database

connection  –  default: null

PDO connection

connectionId  –  default: 0

Connection ID (for debugging concurrent connections, not supported by every database driver)

constraintError  –  default: false

Indicates whether the last query caused a constraint violation

databaseLocked  –  default: false

Remembers whether the database is locked for the current transaction (SQLite only)

driverName  –  default: ''

PDO driver name for the current database connection

errorMessage  –  default: null

Last error message

instance  –  default: null

Singleton instance

lastAutoValue  –  default: null

Last generated auto value (from auto increment column or implicitly used sequence, triggered by a UnbDbAutoValue parameter)

queryCount  –  default: 0

Statistics data: Number of queries run in this session

rowsAffected  –  default: 0

Cached value: Number of rows affected by the last SQL statement (only for DELETE, INSERT and UPDATE)

tablePrefix  –  default: ''

Table prefix, allows storing several UNB tables instances in a single database (schema)

totalTime  –  default: 0.0

Statistics data: Total time that all queries took

transactionLevel  –  default: 0

Current transaction nesting level (only one transaction at a time is used in the database backend)

Constants

DisplayQueryErrors true

Display queries and error messages when an error occurs.

File: database.class.php, line 26
DisplayQueryInfo false

Display information for all issued queries. (Ineffective if DisplayQueryErrors is false.)

File: database.class.php, line 28

Implementation file: database.class.php, line 23

© 2011 Yves Goergen. UNB Components Homepage. Reference generated on 2011-02-22.