Class cDatabases

cDatabases
Direct Known Subclasses:
usageTrack

class cDatabases

This is a wrapper class used to provide a common access interface for all the RDBMS specific classes. Use this classes methods to set and/or retrieve a database object. "Dummy" methods are provided which mirror the database operation methods in the access classes which provides a common interface to the operations without the need for long overload statements. The actual database operations are performed by using methods detailed in the cFrontBase(), cPostgreSQL(), cMSSQL, cODBC(), and cMYSQL classes.

Useage:

require("databases.inc");

$obj = &new cDatabases();
$obj->Set("MYSQL");

$result = $obj->Query($sql);
$row = $obj->FetchRow($result);
etc.....

N.B. Depending on your PHP config, the "= &new" syntax may cause a parse error. If this is the case, use "= new" instead.

Field Summary
obj $current_db
          This variable is used to store the internal object of the currently selected database.
array $database_types
          This variable is array of the objects created for the various databases suuported by this abstraction layer.
 
Constructor Summary
void cDatabases()
          The class contructor checks to see whether FrontBase, MS SQL Server, ODBC, and mySQL support is enabled in PHP then creates, registers and stores objects for any of the above databases supported.
 
Method Summary
 int ColumnLength(resource result, int column_offset)
          Used to access the ColumnLength method of the currently set database object.
 string ColumnName(resource result, int column_offset)
          Used to access the ColumnName method of the currently set database object..
 string ColumnType(resource result, int column_offset)
          Used to access the ColumnType method of the currently set database object..
 void Connect(string hostname, string username, string password, string database)
          Used to access the Connect method of the currently set database object..
 void Disconnect()
          Used to access the Disconnect method of the currently set database object..
 array FetchRow(resource result [, int array_type])
          Used to access the FetchRow method of the currently set database object..
 void FreeResult(resource result)
          Used to access the FreeResult method of the currently set database object..
 obj Get(string database [, int set_internal_obj])
          The get method is used to retrieve and return the object for the database you desire to use.
 string GetLastMessage()
          Used to access the GetLastMessage method of the currently set database object..
 boolean NextResult(resource result)
          Used to access the NextResult method of the currently set database object.
 int NumRows(resource result)
          Used to access the NumRows method of the currently set database object.
 int Query(string sql_query)
          Used to access the Query method of the currently set database object.
void Register(string database, obj database_object)
          The Register method is called by the constructor during the class instantiation.
 void Set(string database)
          The set method is used to set the select the database spefied by $type without returning an object variable.
 

Field Detail

$database_types

array $database_types
This variable is array of the objects created for the various databases suuported by this abstraction layer. The array uses associative keys, named after the databases in question, to store the object. Currently supported index names are:

FRONTBASE
MSSQL
ODBC
MYSQL

$current_db

obj $current_db
This variable is used to store the internal object of the currently selected database. It is intended for internal use by member methods of any classes you may write which extend this class. The Get() method should be used for external script access.
Constructor Detail

cDatabases

void cDatabases()
The class contructor checks to see whether FrontBase, MS SQL Server, ODBC, and mySQL support is enabled in PHP then creates, registers and stores objects for any of the above databases supported.
Method Detail

ColumnName

string ColumnName(resource resource_id, int column_offset)
Used to get the name of the column specified by column_offset in the result set identifed by resource_id. Returns a string containing the column's name on success and null on failure.

Parameters:
resource_id - the resource indentifer returned by Query()
column_offset - the number of the column who's name will returned

ColumnLength

int ColumnLength(resource resource_id, int column_offset)
Used to get the maximum length of column, column_offset, from result, resource_id. Returns the maximum length as an integer on success and null on failure.

Parameters:
resource_id - the resource indentifer returned by Query()
column_offset - the number of the column who's field length will returned

ColumnType

string ColumnType(resource resource_id, int column_offset)
Used to get the datatype of column, column_offset, from result set, resource_id. Returns a the datatype as a string on success and null on error.

Parameters:
resource_id - the resource indentifer returned by Query()
column_offset - the number of the column who's datatype will returned

Connect

void Connect(string hostname, string username, string password, string database)
This method is used to connect to the current database server. You *must* call the Set() method first to indicate which database server you're going to use. All accepted arguments are strings.

Parameters:
hostname - the name/address of the server to connect to
username - the username to use for the database connection
password - the password for the specified username
database - the name of the database to use [optional]

Disconnect

void Disconnect()
Used to disconnect the current database connection.

FetchRow

array FetchRow(resource resource_id [, int array_type])
Used to read the current returned row from resource_id into an array. Array types are defined by the option array_type parameter, the default return is a numerically indexed array. Returns an array containing the row's values indexed by column number or success, or false if no further rows exist in the result set. can contain.

Parameters:
resource_id - the resource indentifer returned by Query()
array_type - the type of array indexing to use

array_type values:
1 => returns an array with associative indices
2 => returns an array with numerical indices (default)
3 => returns an array with both associative and numerical indices

FreeResult

void FreeResult(resource resource_id)
Used to free the current result set, resource_id, from memory.

Parameters:
resource_id - the resource indentifer returned by Query()

Get

obj Get (string database [, int set_internal_obj])
The get method is used to retrieve and return the object for the database you desire to use. It also optionally sets the variables which stores the currently selected database object internally.  This optional is disabled by default. 

Parameters:
database - the database to select.

Accepted Values: "FRONTBASE", "POSTGRES", "MSSQL", "ODBC", or "MYSQL"

set_internal_obj - the flag which indicates whether to set the class's current db object var.

Accepted Values: 1 => set; 0 => don't set (the default)

GetLastMessage

string GetLastMessage()
Used to get the text of the most recent error message on the current database connection. Returns the most recent error message as a string if such a message exists. Otherwise it returns boolean false.

NextResult

boolean NextResult(resource resource_id)
Used to switch to the next result set in the case of multiple record sets being returned from a stored procedure. Returns true if another result set exists, false if not further result sets are found. Updates the $columns and $rows variables from the cDBConstruct() class with the new result set's values.

Parameters:
resource_id - the resource indentifer returned by Query()

NumRows

int NumRows(resource resource_id)
Used to get and return the number of rows in a result set.

Parameters:
resource_id - the resource indentifer returned by Query()

Query

int Query(string sql_query)
Used to execute SQL queries on the currently opened database connection. Updates the $columns and $rows variables from the cDBConstruct() class with the values specific to the passed query. Returns a resource identifier on success or false on failure.

Parameters:
sql_query - the SQL query to execute on the current data connection

Register

void Register (string database, obj database_object)
The Register method is called by the constructor during the class instantiation. It is used to the create instances of the database specific classes, and register those objects with the $database_types array used to store those objects. There is no need to ever call this function directly. 

Parameters:
database - the database to select.

Accepted Values: "FRONTBASE", "POSTGRES", "MSSQL", "ODBC", or "MYSQL"

database_object - the object returned from an instanciation of one of the db specific classes

Set

void Set (string database)
The set method is used to set the select the database specified by database without returning an object variable. It is intended to be used by classes which extend the cDatabases() and where creating a new object variable would have little or negative impact on the programs performance. 

Parameters:
database - the database to select.

Accepted Values: "FRONTBASE", "POSTGRES", "MSSQL", "ODBC", or "MYSQL"