Class Database

Description

Database interaction abstract class definition

Located in /class.database.php (line 23)


                
			
Direct descendents
Class Description
PostgresDatabase Database adapter class for PostgreSQL
Class Constant Summary
 JoinTypeInner = "inner"
 JoinTypeLeft = "left"
Variable Summary
static mixed $aConnections
static mixed $aDefaultProfile
static mixed $aJoinTypes
static mixed $aProfiles
Method Summary
static void AddProfile (array $aProfile)
static Database GetConnection ([array $aProfile = array()])
static void SetDefaultProfile (string $sProfile)
void Begin ()
void CacheSchemas (boolean $bEnable)
void Commit ()
int CountFromResult ( &$rResult, resource $rResult)
string FormatData (string $sType, string $sValue)
string GetColumnType (string $sTableName, string $sFieldName)
array GetDatabases ()
string GetLastError ()
resource GetResource ()
array GetSchema (string $sTableName)
array GetTableColumns (string $sTableName)
array GetTableForeignKeys (string $sTableName)
array GetTablePrimaryKey (string $sTableName)
array GetTables ()
string GetVersion ()
object The PullNextResult ( &$rResult, resource $rResult)
ResultSet Query (string $sSQL)
bool ResetResult ( &$rResult, resource $rResult)
void Rollback ()
void SetCacheDirectory (string $sDirectoryName)
bool TableExists (string $sTableName)
Variables
static mixed $aConnections = array() (line 52)

Stores an a list of existing database connections

  • access: protected
static mixed $aDefaultProfile = array() (line 47)

Stores information about the default database profile

  • access: protected
static mixed $aJoinTypes = array(
self::JoinTypeInner => "INNER JOIN",
self::JoinTypeLeft => "LEFT JOIN"
)
(line 34)

Defines the syntax for the join type constants

  • access: public
static mixed $aProfiles = array() (line 42)

Stores a list of known database profiles

  • access: protected
Methods
static method AddProfile (line 61)

Adds a database profile to the list of known database profiles. These profiles contain connection information for the database, including driver, host, name, user and password.

  • access: public
static void AddProfile (array $aProfile)
  • array $aProfile: The profile array with database connection information
static method GetConnection (line 121)

As the constructor of the Database class and all derived database drivers is protected, the database class cannot be instantiated directly. Instead, the GetConnection() method must be called, afterwhich a database driver object is returned.

A database profile array may be specified to control which database is connected to, and with what driver. If no profile is passed to this method, it first checks to see if there is a default database profile set up. If so, it uses that, if not, it then checks to see if there is only one profile stored. If so, that profile is used. If none of these conditions are met, an exception is thrown.

  • return: A database object; the type depends on the database driver being used. This object contains an active connection to the database.
  • access: public
static Database GetConnection ([array $aProfile = array()])
  • array $aProfile: Optional; The profile array with database connection information. If not supplied, and a profile is already loaded, that profile will be used. If no profile is supplied and more than one profile has been loaded, an exception is thrown.
static method SetDefaultProfile (line 92)

Sets the default database connection profile to the one specified in the first argument.

The default profile is used to create or return a database connection by GetConnection() when no connection is specified to that method.

  • access: public
static void SetDefaultProfile (string $sProfile)
  • string $sProfile: The name of the profile to be used as the default database profile
Begin (line 239)

The Begin() method begins a database transaction which persists until either Commit() or Rollback() is called, or the request ends. If Commit() is not called before the end of the request, the database transaction will automatically roll back.

  • abstract:
  • access: public
void Begin ()

Redefined in descendants as:
  • PostgresDatabase::Begin() : The Begin() method begins a database transaction which persists until either Commit() or Rollback() is called, or the request ends. If Commit() is not called before the end of the request, the database transaction will automatically roll back.
CacheSchemas (line 286)

The CacheSchemas() method toggles whether or not database schemas discovered through the GetSchema(), GetTableColumns(), GetTableForeignKeys() and GetTablePrimaryKey() methods should be cached, and also whether or not those methods will pull their information from a cache, if available.

  • abstract:
  • access: public
void CacheSchemas (boolean $bEnable)
  • boolean $bEnable: Toggles whether or not to cache discovered database schemas

Redefined in descendants as:
  • PostgresDatabase::CacheSchemas() : The CacheSchemas() method toggles whether or not database schemas discovered through the GetSchema(), GetTableColumns(), GetTableForeignKeys() and GetTablePrimaryKey() methods should be cached, and also whether or not those methods will pull their information from a cache, if available.
Commit (line 247)

The Commit() method commits a database transaction (assuming one was started with Begin()). If Commit() is not called before the end of the request, the database transaction will automatically roll back.

  • abstract:
  • access: public
void Commit ()

Redefined in descendants as:
  • PostgresDatabase::Commit() : The Commit() method commits a database transaction (assuming one was started with Begin()). If Commit() is not called before the end of the request, the database transaction will automatically roll back.
CountFromResult (line 221)

Returns the number of results from the last query performed on the specified database resource object.

  • return: The number of rows in the specified database resource
  • abstract:
  • access: public
int CountFromResult ( &$rResult, resource $rResult)
  • resource $rResult: The database connection resource
  • &$rResult

Redefined in descendants as:
FormatData (line 305)

Returns a database-safe formatted representation of the supplied data, based on the supplied data type.

  • return: A string of the formatted value supplied.
  • abstract:
  • access: public
string FormatData (string $sType, string $sValue)
  • string $sType: The data type of the supplied value.
  • string $sValue: The value to be formatted into a database-safe representation.

Redefined in descendants as:
GetColumnType (line 389)

Returns the data type of the specified column in the specified table.

  • return: The data type of the column, if one is found, or null.
  • abstract:
  • access: public
string GetColumnType (string $sTableName, string $sFieldName)
  • string $sTableName: The name of the table that the desired column belongs to
  • string $sFieldName: The name of the column that is desired to know the type of

Redefined in descendants as:
GetDatabases (line 322)

This method returns all databases on the database server.

  • return: An array of all databases on the database server in the formation of database_name => database_name
  • abstract:
  • access: public
array GetDatabases ()

Redefined in descendants as:
GetLastError (line 263)

Returns the last database error, if any.

  • return: A string representation of the last error
  • abstract:
  • access: public
string GetLastError ()

Redefined in descendants as:
GetResource (line 294)

Returns the PHP native database connection resource.

  • return: A database connection resource.
  • abstract:
  • access: public
resource GetResource ()

Redefined in descendants as:
GetSchema (line 337)

Collects information about the schema for the specified table, including information on columns (name, datatype), primary keys and foreign keys (relationships to other tables).

This method stores its information the static variable $aSchemas so that if the data is required again, the database does not have to be consoluted.

If schema caching is on, this method can pull data from a schema cache.

  • return: An array of schema information for the specified table
  • abstract:
  • access: public
array GetSchema (string $sTableName)
  • string $sTableName: The name of the table for the requested schema

Redefined in descendants as:
GetTableColumns (line 351)

Returns an array of columns that belong to the specified table.

This method stores its information the static variable $aSchemas so that if the data is required again, the database does not have to be consoluted.

If schema caching is on, this method can pull data from a schema cache.

  • return: An array of columns that belong to the specified table
  • abstract:
  • access: public
array GetTableColumns (string $sTableName)
  • string $sTableName: The name of the table for the requested columns

Redefined in descendants as:
GetTableForeignKeys (line 379)

Returns an array of relationships (foreign keys) for the specified table.

This method stores its information the static variable $aSchemas so that if the data is required again, the database does not have to be consoluted.

If schema caching is on, this method can pull data from a schema cache.

  • return: An array of relationships for the specified table
  • abstract:
  • access: public
array GetTableForeignKeys (string $sTableName)
  • string $sTableName: The name of the table for the requested relationships

Redefined in descendants as:
GetTablePrimaryKey (line 365)

Returns an array of columns that belong to the primary key for the specified table.

This method stores its information the static variable $aSchemas so that if the data is required again, the database does not have to be consoluted.

If schema caching is on, this method can pull data from a schema cache.

  • return: An array of columns that belong to the primary key for the specified table
  • abstract:
  • access: public
array GetTablePrimaryKey (string $sTableName)
  • string $sTableName: The name of the table for the requested primary key

Redefined in descendants as:
GetTables (line 313)

This method returns all tables for the database the class is currently connected to.

  • return: Returns an array of all tables in the form of table_name => table_name.
  • abstract:
  • access: public
array GetTables ()

Redefined in descendants as:
GetVersion (line 407)

Returns the version of the database server.

  • return: The database server version reported by the database server
  • abstract:
  • access: public
string GetVersion ()

Redefined in descendants as:
PullNextResult (line 211)

Pulls the next record from specified database resource and returns it as an object.

  • return: next record from the database, or null if there are no more records
  • abstract:
  • access: public
object The PullNextResult ( &$rResult, resource $rResult)
  • resource $rResult: The database connection resource to pull the next record from
  • &$rResult

Redefined in descendants as:
Query (line 202)

Queries the database using the supplied SQL query.

  • return: A ResultSet object containing the results of the database query
  • abstract:
  • access: public
ResultSet Query (string $sSQL)
  • string $sSQL: The SQL query to execute

Redefined in descendants as:
ResetResult (line 231)

Attempts to return the internal pointer of the specified database resource to the first row.

  • return: True if the operation was successful, false otherwise
  • abstract:
  • access: public
bool ResetResult ( &$rResult, resource $rResult)
  • resource $rResult: The database connection resource to pull the next record from
  • &$rResult

Redefined in descendants as:
Rollback (line 255)

The Rollback() method rolls back a database transaction (assuming one was started with Begin()). The database transaction is automatically rolled back if Commit() is not called.

  • abstract:
  • access: public
void Rollback ()

Redefined in descendants as:
  • PostgresDatabase::Rollback() : The Rollback() method rolls back a database transaction (assuming one was started with Begin()). The database transaction is automatically rolled back if Commit() is not called.
SetCacheDirectory (line 275)

The SetCacheDirectory() method stores which directory should be used to load and store database schema cache files. If the directory does not exist, an exception will be thrown. Setting the cache directory is useless unless schema caching is turned on using CacheSchemas().

  • abstract:
  • access: public
void SetCacheDirectory (string $sDirectoryName)
  • string $sDirectoryName: The absolute path to the directory in the system to store and read cached database schema files.

Redefined in descendants as:
  • PostgresDatabase::SetCacheDirectory() : The SetCacheDirectory() method stores which directory should be used to load and store database schema cache files. If the directory does not exist, an exception will be thrown.
TableExists (line 398)

Determines whether the specified table exists in the current database.

  • return: True or false, depending on whether the table exists.
  • abstract:
  • access: public
bool TableExists (string $sTableName)
  • string $sTableName: The name of the table to determine existence

Redefined in descendants as:
Class Constants
JoinTypeInner = "inner" (line 28)

Class constants for query join types (used for CRUD operations)

JoinTypeLeft = "left" (line 29)

Documentation generated on Thu, 25 Feb 2010 15:59:40 -0500 by phpDocumentor 1.4.3