CWIS Developer Documentation

- Home
- Main Page
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

List of all members
Database Class Reference

SQL database abstraction object with smart query caching. More...

## Setup/Initialization
| Database ($UserName=NULL, $Password=NULL, $DatabaseName=NULL, $HostName=NULL)
| Object constructor. More...
| __sleep ()
| __wakeup ()
| Restore database connection when unserialized. More...
| SetDefaultStorageEngine ($Engine)
| Set default database storage engine. More...
| GetServerVersion ()
| Get database server version number. More...
| DBHostName ()
| Get host name of system on which database server resides. More...
| DBName ()
| Get current database name. More...
| DBUserName ()
| Get name used to connect with database server. More...
| SetQueryErrorsToIgnore ($ErrorsToIgnore, $NormalizeWhitespace=TRUE)
| Set query errors to ignore. More...
| IgnoredError ()
| Check whether an error was ignored by the most recent query. More...
static | SetGlobalServerInfo ($UserName, $Password, $HostName="localhost")
static | SetGlobalDatabaseName ($DatabaseName)
| Set default database name. More...
static | Caching ($NewSetting=NULL)
| Get or set whether query result caching is currently enabled. More...
static | AdvancedCaching ($NewSetting=NULL)
| Get or set whether advanced query result cachine is currently enabled. More...

## Data Manipulation
| Query ($QueryString, $FieldName="")
| Query database (with caching if enabled). More...
| ExecuteQueriesFromFile ($FileName)
| Execute queries from specified file. More...
| QueryErrMsg ()
| Get most recent error message text set by Query(). More...
| QueryErrNo ()
| Get most recent error code set by Query(). More...
| NumRowsSelected ()
| Get number of rows returned by last query. More...
| FetchRow ()
| Get next database row retrieved by most recent query. More...
| FetchRows ($NumberOfRows=NULL)
| Get specified number of database rows retrieved by most recent query. More...
| FetchColumn ($FieldName, $IndexFieldName=NULL)
| Get all available values for specified database field retrieved by most recent query. More...
| FetchField ($FieldName)
| Pull next row from last DB query and get a specific value from that row. More...
| LastInsertId ()
| Get ID of row added by the last SQL "INSERT" statement. More...
| UpdateValue ($TableName, $FieldName, $NewValue, $Condition, &$CachedRecord)
| A convenience function to get or set a value in the database. More...
| UpdateIntValue ($TableName, $FieldName, $NewValue, $Condition, &$CachedRecord)
| A convenience function to get or set an integer value in the database. More...
| UpdateFloatValue ($TableName, $FieldName, $NewValue, $Condition, &$CachedRecord)
| A convenience function to get or set a float value in the database. More...
static | DisplayQueryErrors ($NewValue=NULL)
| Get/set whether Query() errors will be displayed. More...

## Miscellaneous
| $DBUserName
| $DBPassword
| $DBHostName
| $DBName
| LogComment ($String)
| Peform query that consists of SQL comment statement. More...
| TableExists ($TableName)
| Get whether specified table exists. More...
| FieldExists ($TableName, $FieldName)
| Get whether specified field exists in specified table. More...
| GetFieldType ($TableName, $FieldName)
| Get field (column) type. More...
static | QueryDebugOutput ($NewSetting)
| Enable or disable debugging output for queries. More...
static | NumQueries ()
| Get the number of queries that have been run since program execution began. More...
static | NumCacheHits ()
| Get the number of queries that have resulted in cache hits since program execution began. More...
static | CacheHitRate ()
| Get the ratio of query cache hits to queries as a percentage. More...

## Detailed Description

SQL database abstraction object with smart query caching.

Definition at line 22 of file Axis--Database.php.

## Member Function Documentation

Database::__sleep | ( |  | ) |

Specify variables to be saved when serialized.

Definition at line 80 of file Axis--Database.php.

Database::__wakeup | ( |  | ) |

Restore database connection when unserialized.

Definition at line 87 of file Axis--Database.php.

References DBHostName(), DBName(), and DBUserName().

static Database::AdvancedCaching | ( |  | $NewSetting = `NULL` | ) |
| static

Get or set whether advanced query result cachine is currently enabled.

Advanced caching attempts to determine whether a query has modified any of the referenced tables since the data was last cached. Advanced caching is disabled by default. This setting applies to all instances of the Database class.

Parameters

  bool | $NewSetting | TRUE to enable advanced caching or FALSE to disable. (OPTIONAL)

Returns
  Current advanced caching setting.

Definition at line 216 of file Axis--Database.php.

static Database::CacheHitRate | ( |  | ) |
| static

Get the ratio of query cache hits to queries as a percentage.

The value returned is for all instances of the Database class.

Returns
  Percentage of queries that resulted in hits.

Definition at line 869 of file Axis--Database.php.

static Database::Caching | ( |  | $NewSetting = `NULL` | ) |
| static

Get or set whether query result caching is currently enabled.

Caching is enabled by default. This setting applies to all instances of the Database class.

Parameters

  bool | $NewSetting | TRUE to enable caching or FALSE to disable. (OPTIONAL)

Returns
  Current caching setting.

Definition at line 190 of file Axis--Database.php.

Database::Database | ( |  | $UserName = `NULL`,
|  |  | $Password = `NULL`,
|  |  | $DatabaseName = `NULL`,
|  |  | $HostName = `NULL`
| ) |  |

Object constructor.

If user name, password, or database name are omitted they must have been set earlier with SetGlobalServerInfo() and SetGlobalDatabaseName().

Parameters

  string | $UserName | User name to use to log in to database server. (OPTIONAL)
  string | $Password | Password to use to log in to database server. (OPTIONAL)
  string | $DatabaseName | Name of database to use once logged in. (OPTIONAL)
  string | $HostName | Host name of system on which database server resides. (OPTIONAL, defaults to "localhost")

See also
  Database::SetGlobalServerInfo()
  Database::SetGlobalDatabaseName()

Definition at line 40 of file Axis--Database.php.

References $DBName, DBHostName(), DBName(), and DBUserName().

Database::DBHostName | ( |  | ) |

Get host name of system on which database server resides.

Returns
  Host name of database server.

See also
  SetGlobalServerInfo()

Definition at line 167 of file Axis--Database.php.

References $DBHostName.

Referenced by __wakeup(), and Database().

Here is the caller graph for this function:

Database::DBName | ( |  | ) |

Get current database name.

Returns
  Database name.

See also
  SetGlobalDatabaseName()

Definition at line 174 of file Axis--Database.php.

References $DBName.

Referenced by __wakeup(), and Database().

Here is the caller graph for this function:

Database::DBUserName | ( |  | ) |

Get name used to connect with database server.

Returns
  Login name.

See also
  SetGlobalServerInfo()

Definition at line 181 of file Axis--Database.php.

References $DBUserName.

Referenced by __wakeup(), and Database().

Here is the caller graph for this function:

static Database::DisplayQueryErrors | ( |  | $NewValue = `NULL` | ) |
| static

Get/set whether Query() errors will be displayed.

By default errors are not displayed.

Parameters

  bool | $NewValue | TRUE to display errors or FALSE to not display. (OPTIONAL)

Returns
  Current value of whether Query() errors will be displayed.

Definition at line 527 of file Axis--Database.php.

Referenced by MetadataSchema\GetRowsForUpgrade().

Here is the caller graph for this function:

Database::ExecuteQueriesFromFile | ( |  | $FileName | ) |

Execute queries from specified file.

Comment lines are ignored. Multiple queries on a single line are not handled. Execution continues until all queries are run or an error occurs that has not been previously specified to be ignored. If a query fails, information about the failure can be retrieved with QueryErrMsg() and QueryErrNo().

Parameters

  string | $FileName | Name of file to load queries from.

Returns
  Number of queries executed or NULL if query failed.

See also
  Database::SetQueryErrorsToIgnore()
  Database::QueryErrMsg()
  Database::QueryErrNo()

Definition at line 447 of file Axis--Database.php.

References Query().

Database::FetchColumn | ( |  | $FieldName,
|  |  | $IndexFieldName = `NULL`
| ) |  |

Get all available values for specified database field retrieved by most recent query.

If a second database field name is specified then the array returned will be indexed by the values from that field. If all index field values are not unique then some values will be overwritten.

A common use for this method is to retrieve a set of values with an ID field specified for the index:
`$CNames = $DB->FetchColumn("ControlledName", "ControlledNameId");`

Parameters

  string | $FieldName | Name of database field.
  string | $IndexFieldName | Name of second database field to use for array index. (OPTIONAL)

Returns
  Array of values from specified field, indexed numerically. If IndexFieldName is supplied then array will be indexed by corresponding values from that field.

Definition at line 643 of file Axis--Database.php.

References FetchRow().

Database::FetchField | ( |  | $FieldName | ) |

Pull next row from last DB query and get a specific value from that row.

This is a convenience method that in effect combines a FetchRow() with getting a value from the array returned. This method does advance the pointer to the next row returned by the query each time it is called.

Parameters

  string | $FieldName | Name of field.

Returns
  Value from specified field.

Definition at line 668 of file Axis--Database.php.

References FetchRow().

Referenced by FieldExists(), GetFieldType(), and Query().

Here is the caller graph for this function:

Database::FetchRow | ( |  | ) |

Get next database row retrieved by most recent query.

Returns
  Array of database values with field names for indexes. Returns FALSE if no more rows are available.

Definition at line 563 of file Axis--Database.php.

Referenced by MysqlSystemVariables\__construct(), MetadataFieldOrder\__construct(), FetchColumn(), FetchField(), FetchRows(), and UpdateValue().

Here is the caller graph for this function:

Database::FetchRows | ( |  | $NumberOfRows = `NULL` | ) |

Get specified number of database rows retrieved by most recent query.

Parameters

  int | $NumberOfRows | Maximum number of rows to return. (OPTIONAL – if not specified then all available rows are returned)

Returns
  Array of rows. Each row is an associative array indexed by field name.

Definition at line 608 of file Axis--Database.php.

References FetchRow().

Database::FieldExists | ( |  | $TableName,
|  |  | $FieldName
| ) |  |

Get whether specified field exists in specified table.

Parameters

  string | $TableName | Name of database table.
  string | $FieldName | Name of database field.

Returns
  bool TRUE if table and field exist, or FALSE otherwise.

Definition at line 811 of file Axis--Database.php.

References FetchField(), and Query().

Database::GetFieldType | ( |  | $TableName,
|  |  | $FieldName
| ) |  |

Get field (column) type.

Parameters

  string | $TableName | Name of database table.
  string | $FieldName | Name of database field.

Returns
  string Field type or NULL if field was not found.

Definition at line 827 of file Axis--Database.php.

References FetchField(), and Query().

Database::GetServerVersion | ( |  | ) |

Get database server version number.

Returns
  string Version number.

Definition at line 149 of file Axis--Database.php.

References Query().

Referenced by SetDefaultStorageEngine().

Here is the caller graph for this function:

Database::IgnoredError | ( |  | ) |

Check whether an error was ignored by the most recent query.

Returns
  mixed Error message if an error was ignored, otherwise FALSE.

See also
  Database::SetQueryErrorsToIgnore()

Definition at line 264 of file Axis--Database.php.

Database::LastInsertId | ( |  | ) |

Get ID of row added by the last SQL "INSERT" statement.

It should be called immediately after the INSERT statement query. This method uses the SQL "LAST_INSERT_ID()" function.

Returns
  Numerical ID value.

Definition at line 680 of file Axis--Database.php.

References Query().

Database::LogComment | ( |  | $String | ) |

Peform query that consists of SQL comment statement.

This is used primarily when query debug output is turned on, to insert additional information into the query stream.

Parameters

  string | $String | Debug string.

Definition at line 789 of file Axis--Database.php.

References Query().

static Database::NumCacheHits | ( |  | ) |
| static

Get the number of queries that have resulted in cache hits since program execution began.

The value returned is for all instances of the Database class.

Returns
  Number of queries that resulted in cache hits.

Definition at line 859 of file Axis--Database.php.

static Database::NumQueries | ( |  | ) |
| static

Get the number of queries that have been run since program execution began.

The value returned is for all instances of the Database class.

Returns
  Number of queries.

Definition at line 848 of file Axis--Database.php.

Database::NumRowsSelected | ( |  | ) |

Get number of rows returned by last query.

Returns
  Number of database rows selected by last query.

Definition at line 537 of file Axis--Database.php.

Referenced by MetadataFieldOrder\__construct(), and TableExists().

Here is the caller graph for this function:

Database::Query | ( |  | $QueryString,
|  |  | $FieldName = `""`
| ) |  |

Query database (with caching if enabled).

Parameters

  string | $QueryString | SQL query string.
  string | $FieldName | Name of field for which to return value to caller. (OPTIONAL)

Returns
  Query handle, retrieved value (if FieldName supplied), or FALSE on error.

Definition at line 279 of file Axis--Database.php.

References FetchField().

Referenced by MysqlSystemVariables\__construct(), MetadataFieldOrder\__construct(), MetadataFieldOrder\Delete(), ExecuteQueriesFromFile(), FieldExists(), GetFieldType(), GetServerVersion(), LastInsertId(), LogComment(), SetDefaultStorageEngine(), TableExists(), and UpdateValue().

Here is the caller graph for this function:

static Database::QueryDebugOutput | ( |  | $NewSetting | ) |
| static

Enable or disable debugging output for queries.

Output is disabled by default. This setting applies to all instances of the Database class.

Parameters

  bool | $NewSetting | TRUE to enable output or FALSE to disable output.

Definition at line 838 of file Axis--Database.php.

Database::QueryErrMsg | ( |  | ) |

Get most recent error message text set by Query().

Returns
  Error message text from database server.

See also
  QueryErrNo()

Definition at line 506 of file Axis--Database.php.

Database::QueryErrNo | ( |  | ) |

Get most recent error code set by Query().

Returns
  Error code from database server.

See also
  QueryErrMsg()

Definition at line 516 of file Axis--Database.php.

Database::SetDefaultStorageEngine | ( |  | $Engine | ) |

Set default database storage engine.

Parameters

  string | $Engine | New default storage engine.

Definition at line 135 of file Axis--Database.php.

References GetServerVersion(), and Query().

static Database::SetGlobalDatabaseName | ( |  | $DatabaseName | ) |
| static

Set default database name.

Parameters

  string | $DatabaseName | Name of database to use once logged in.

Definition at line 122 of file Axis--Database.php.

static Database::SetGlobalServerInfo | ( |  | $UserName,
|  |  | $Password,
|  |  | $HostName = `"localhost"`
| ) |  |
| static

Set default login and host info for database server.

Parameters

  string | $UserName | User name to use to log in to database server.
  string | $Password | Password to use to log in to database server.
  string | $HostName | Host name of system on which database server resides. (OPTIONAL, defaults to "localhost")

Definition at line 107 of file Axis--Database.php.

Database::SetQueryErrorsToIgnore | ( |  | $ErrorsToIgnore,
|  |  | $NormalizeWhitespace = `TRUE`
| ) |  |

Set query errors to ignore.

The command and error message patterns should be formatted for preg_match(). For example:

$SqlErrorsWeCanIgnore = array(
"/ALTER TABLE [a-z]+ ADD COLUMN/i" => "/Duplicate column name/i",
"/CREATE TABLE /i" => "/Table '[a-z0-9_]+' already exists/i",
);

Parameters

  array | $ErrorsToIgnore | Associative array containing errors to ignore when running queries, with patterns for SQL commands as the indexes and the patterns for the SQL error messages as the values. Pass in NULL to clear list of errors to ignore.
  bool | $NormalizeWhitespace | If TRUE, incoming SQL patterns have any whitespace within them replaced with "\s+" so that variations in whitespace within SQL will not cause the pattern to fail. (OPTIONAL, defaults to TRUE)

See also
  Database::IgnoredError()

Definition at line 244 of file Axis--Database.php.

Database::TableExists | ( |  | $TableName | ) |

Get whether specified table exists.

Parameters

  string | $TableName | Name of database table.

Returns
  bool TRUE if table exists, or FALSE otherwise.

Definition at line 799 of file Axis--Database.php.

References NumRowsSelected(), and Query().

Database::UpdateFloatValue | ( |  | $TableName,
|  |  | $FieldName,
|  |  | $NewValue,
|  |  | $Condition,
|  | & | $CachedRecord
| ) |  |

A convenience function to get or set a float value in the database.

This will typically be called from inside a private convenience method within an object that supplies the table name, condition, and cache. This method should be used instead of UpdateValue() in situations where the incoming value specifically needs to be forced to an float.

Parameters

  string | $TableName | Name of database table.
  string | $FieldName | Name of database field.
  float | $NewValue | New value to set. Use DB_NOVALUE to not set a new value (i.e. when just getting a value).
  string | $Condition | SQL query conditional to use in SELECT or UPDATE statements (should not include "WHERE"). Use NULL if no conditional is needed.
  array | $CachedRecord | Variable to use to cache values. Accessed by reference.

Returns
  Requested value.

Definition at line 772 of file Axis--Database.php.

References DB_NOVALUE, and UpdateValue().

Database::UpdateIntValue | ( |  | $TableName,
|  |  | $FieldName,
|  |  | $NewValue,
|  |  | $Condition,
|  | & | $CachedRecord
| ) |  |

A convenience function to get or set an integer value in the database.

This will typically be called from inside a private convenience method within an object that supplies the table name, condition, and cache. This method should be used instead of UpdateValue() in situations where the incoming value specifically needs to be forced to an int.

Parameters

  string | $TableName | Name of database table.
  string | $FieldName | Name of database field.
  int | $NewValue | New value to set. Use DB_NOVALUE to not set a new value (i.e. when just getting a value).
  string | $Condition | SQL query conditional to use in SELECT or UPDATE statements (should not include "WHERE"). Use NULL if no conditional is needed.
  array | $CachedRecord | Variable to use to cache values. Accessed by reference.

Returns
  Requested value.

Definition at line 748 of file Axis--Database.php.

References DB_NOVALUE, and UpdateValue().

Database::UpdateValue | ( |  | $TableName,
|  |  | $FieldName,
|  |  | $NewValue,
|  |  | $Condition,
|  | & | $CachedRecord
| ) |  |

A convenience function to get or set a value in the database.

This will typically be called from inside a private convenience method within an object that supplies the table name, condition, and cache.

Parameters

  string | $TableName | Name of database table.
  string | $FieldName | Name of database field.
  mixed | $NewValue | New value to set. Use DB_NOVALUE to not set a new value (i.e. when just getting a value).
  string | $Condition | SQL query conditional to use in SELECT or UPDATE statements (should not include "WHERE"). Use NULL if no conditional is needed.
  array | $CachedRecord | Variable to use to cache values. Accessed by reference.

Returns
  Requested value.

Definition at line 701 of file Axis--Database.php.

References DB_NOVALUE, FetchRow(), and Query().

Referenced by UpdateFloatValue(), and UpdateIntValue().

Here is the caller graph for this function:

## Member Data Documentation

Database::$DBHostName
| protected

Definition at line 887 of file Axis--Database.php.

Referenced by DBHostName().

Database::$DBName
| protected

Definition at line 888 of file Axis--Database.php.

Referenced by Database(), and DBName().

Database::$DBPassword
| protected

Definition at line 886 of file Axis--Database.php.

Database::$DBUserName
| protected

Definition at line 885 of file Axis--Database.php.

Referenced by DBUserName().

The documentation for this class was generated from the following file:

- lib/AxisPHP/Axis--Database.php