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.
   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.
S GetInstance Gets the 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.
   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. :-)
   InternalExecute Actually executes an SQL query.
   ProcessSql Basic SQL query processing.
   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
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
instance  –  default: null
Singleton instance
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

© 2010 Yves Goergen. UNB Components Homepage. Reference generated on 2010-03-07.