Class DatabaseConnection

Description

Habari DatabaseConnection Class

Located in /system/classes/databaseconnection.php (line 10)


	
			
Direct descendents
Class Description
SQLiteConnection Habari database specific connection class
MySQLConnection Habari database specific connection class
PGSQLConnection Habari database specific connection class
Variable Summary
mixed $pdo
mixed $prefix
Method Summary
static mixed ConnectionFactory (connection_string $connect_string)
void clear_errors ()
void commit ()
boolean connect (string $connect_string, string $db_user, string $db_pass)
void dbdelta ( $queries, [ $execute = true], [ $silent = true])
boolean delete (string $table, array $keyfields)
boolean disconnect ()
boolean exec (string $query)
mixed execute_procedure (procedure $procedure, [args $args = array()])
boolean exists (string $table, array $keyfieldvalues)
string filter_tables (string $query)
array get_column (string $query, [array $args = array()])
void get_driver_name ()
array get_errors ()
array get_keyvalue (string $query, [array $args = array()])
array get_last_error ()
array get_profiles ()
array get_results (query $query, [args $args = array()], string 2)
object A get_row (string $query, [array $args = array()], string 2)
mixed get_value (string $query, [array $args = array()])
boolean has_errors ()
boolean insert (string $table, array $fieldvalues)
boolean in_transaction ()
boolean is_connected ()
mixed last_insert_id ()
array list_tables ()
void load_tables ()
boolean query (string $query, [array $args = array()])
boolean query_file (string $file)
void register_table (name $name)
void rollback ()
int row_count ()
void set_fetch_class (class_name $class_name)
void set_fetch_mode (mode $mode)
string sql_t (string $query, array $args)
string table (string $name)
boolean update (string $table, array $fieldvalues, array $keyfields)
void upgrade (integer $old_version, [ $upgrade_path = ''])
Variables
mixed $pdo = NULL (line 16)
  • access: protected
mixed $prefix = '' (line 61)
  • access: protected
Methods
static method ConnectionFactory (line 70)

Returns the appropriate type of Connection class for the connect string passed or null on failure

  • return: returns appropriate DatabaseConnection child class instance or errors out if requiring the db class fails
  • access: public
static mixed ConnectionFactory (connection_string $connect_string)
  • connection_string $connect_string: a PDO connection string
begin_transaction (line 359)

Start a transaction against the RDBMS in order to wrap multiple

statements in a safe ACID-compliant container

  • access: public
void begin_transaction ()
clear_errors (line 433)

Updates the last error pointer to simulate resetting the error array

  • access: public
void clear_errors ()
commit (line 381)

Commit a currently running transaction

  • access: public
void commit ()
connect (line 109)

Connect to a database server

  • return: TRUE on success, FALSE on error
  • access: public
boolean connect (string $connect_string, string $db_user, string $db_pass)
  • string $connect_string: a PDO connection string
  • string $db_user: the database user name
  • string $db_pass: the database user password

Redefined in descendants as:
  • SQLiteConnection::connect() : Connect to SQLite Overrides the DatabaseConnection to return false if the SQLite file doesn't exist.
  • MySQLConnection::connect() : Extends default connection method. It will be useful in order to allow accents and other DB-centric global commands.
dbdelta (line 700)

Automatic diffing function, used for determining required database upgrades.

Implemented in child classes.

  • access: public
void dbdelta ( $queries, [ $execute = true], [ $silent = true])
  • $queries
  • $execute
  • $silent

Redefined in descendants as:
  • SQLiteConnection::dbdelta() : automatic diffing function - used for determining required database upgrades based on Owen Winkler's microwiki upgrade function
  • MySQLConnection::dbdelta() : automatic diffing function - used for determining required database upgrades based on Owen Winkler's microwiki upgrade function
  • PGSQLConnection::dbdelta() : automatic diffing function - used for determining required database upgrades based on Owen Winkler's microwiki upgrade function
delete (line 666)

Deletes any record that matches the specific criteria

  • return: True on success, false if not
    1. DB::delete'mytable'array'fieldname' => 'value' ) );
  • access: public
boolean delete (string $table, array $keyfields)
  • string $table: Table to delete from
  • array $keyfields: Associative array of field values to match
disconnect (line 122)

Disconnect from the database server.

  • return: TRUE
  • access: public
boolean disconnect ()
exec (line 206)

Execute the given query on the database. Encapsulates PDO::exec.

WARNING: Make sure you don't call this with a SELECT statement. PDO will buffer the results and leave your cursor dangling.

  • return: TRUE on success, FALSE on error
  • access: public
boolean exec (string $query)
  • string $query: the query to run
execute_procedure (line 296)

Execute a stored procedure

  • return: whatever the procedure returns...
  • todo: EVERYTHING... :)
  • access: public
mixed execute_procedure (procedure $procedure, [args $args = array()])
  • procedure $procedure: name of the stored procedure
  • args $args: arguments for the procedure
exists (line 597)

Checks for a record that matches the specific criteria

  • return: True if any matching record exists, false if not
    1. DB::exists'mytable'array'fieldname' => 'value' ) );
  • access: public
boolean exists (string $table, array $keyfieldvalues)
  • string $table: Table to check
  • array $keyfieldvalues: Associative array of field values to match
filter_tables (line 796)

Replace braced table names with their prefixed counterparts

  • return: The translated query
  • access: public
string filter_tables (string $query)
  • string $query: The query with {braced} table names
get_column (line 512)

Returns all values for a column for a query

  • return: An array containing the column data
    1. $aryDB::get_column'SELECT col1 FROM tablename WHERE foo= ?'array'fieldvalue' ) );
  • access: public
array get_column (string $query, [array $args = array()])
  • string $query: The query to execute
  • array $args: Arguments to pass for prepared statements
get_driver_name (line 801)
  • access: public
void get_driver_name ()
get_errors (line 416)

Returns error data gathered from database connection

  • return: An array of error data
  • access: public
array get_errors ()
get_keyvalue (line 548)

Returns an associative array using the first returned column as the array key and the second as the array value

  • return: An array containing the associative data
    1. $ary$dbconnection->get_keyvalue'SELECT keyfield, valuefield FROM tablename');
  • access: public
array get_keyvalue (string $query, [array $args = array()])
  • string $query: The query to execute
  • array $args: Arguments to pass for prepared statements
get_last_error (line 442)

Returns only the last error info

  • return: Data for the last error
  • access: public
array get_last_error ()
get_profiles (line 392)

Returns query profiles

  • return: an array of query profiles
  • access: public
array get_profiles ()
get_results (line 456)

Execute a query and return the results as an array of objects

  • return: An array of QueryRecord or the named class each containing the row data
    1. $aryDB::get_results'SELECT * FROM tablename WHERE foo= ?'array'fieldvalue' )'extendedQueryRecord' );
  • access: public
array get_results (query $query, [args $args = array()], string 2)
  • string 2: Optional class name for row result objects
  • query $query: the query to execute
  • args $args: array of arguments to pass for prepared statements
get_row (line 483)

Returns a single row (the first in a multi-result set) object for a query

  • return: QueryRecord or an instance of the named class containing the row data
    1. $objDB::get_row'SELECT * FROM tablename WHERE foo= ?'array'fieldvalue' )'extendedQueryRecord' );
  • access: public
object A get_row (string $query, [array $args = array()], string 2)
  • string 2: Optional class name for row result object
  • string $query: The query to execute
  • array $args: Arguments to pass for prepared statements
get_value (line 529)

Return a single value from the database

  • return: a single value ( int, string )
  • access: public
mixed get_value (string $query, [array $args = array()])
  • string $query: the query to execute
  • array $args: Arguments to pass for prepared statements
has_errors (line 425)

Determines if there have been errors since the last clear_errors() call

  • return: True if there were errors, false if not
  • access: public
boolean has_errors ()
insert (line 570)

Inserts into the specified table values associated to the key fields

  • return: True on success, false if not
    1. DB::insert'mytable'array'fieldname' => 'value' ) );
  • access: public
boolean insert (string $table, array $fieldvalues)
  • string $table: The table name
  • array $fieldvalues: An associative array of fields and values to insert
in_transaction (line 144)

Check whether there is a transaction underway.

  • access: public
boolean in_transaction ()
is_connected (line 134)

Check whether there is an existing connection to a database.

  • access: public
boolean is_connected ()
last_insert_id (line 686)

Helper function to return the last inserted sequence or auto_increment field. Useful when doing multiple inserts within a single transaction -- for example, adding dependent related rows.

mixed last_insert_id ()
list_tables (line 824)

Returns a list of tables the DB currently knows about.

  • return: The list of tables.
  • access: public
array list_tables ()
load_tables (line 83)

Populate the table mapping.

  • access: protected
void load_tables ()
query (line 227)

Execute a SQL statement.

  • return: TRUE on success, FALSE on failure
  • access: public
boolean query (string $query, [array $args = array()])
  • string $query: the SQL statement
  • array $args: values for the bound parameters
query_file (line 758)

Load a file containing queries, replace the prefix, execute all queries present

  • return: True on successful execution of all queries
  • access: public
boolean query_file (string $file)
  • string $file: The filename containing the queries
register_table (line 172)

Adds a table to the list of tables known to Habari. Used by Theme and Plugin classes to inform the DB class about custom tables used by the plugin

  • access: public
void register_table (name $name)
  • name $name: the table name
rollback (line 372)

Rolls a currently running transaction back to the prexisting state, or, if the RDBMS supports it, whenever a savepoint was committed.

  • access: public
void rollback ()
row_count (line 814)

Returns number of rows affected by the last DELETE, INSERT, or UPDATE

  • return: The number of rows affected.
  • access: public
int row_count ()
set_fetch_class (line 193)

Sets the class to fetch, if fetch mode is PDO::FETCH_CLASS

  • access: public
void set_fetch_class (class_name $class_name)
  • class_name $class_name: Name of class to create during fetch
set_fetch_mode (line 183)

Sets the fetch mode for return calls from PDOStatement

  • access: public
void set_fetch_mode (mode $mode)
  • mode $mode: One of the PDO::FETCH_MODE integers
sql_t (line 785)

Translates the query for the current database engine

  • return: The translated query
  • access: public
string sql_t (string $query, array $args)
  • string $query: The query to translate for the current database engine
  • array $args: Arguments to the query

Redefined in descendants as:
table (line 155)

Get the full table name for the given table.

  • return: the full table name, or FALSE if the table was not found
  • access: public
string table (string $name)
  • string $name: name of the table
update (line 620)

function update

Updates any record that matches the specific criteria A new row is inserted if no existing record matches the criteria

  • return: True on success, false if not
    1. DB::update'mytable'array'fieldname' => 'newvalue' )array'fieldname' => 'value' ) );
  • access: public
boolean update (string $table, array $fieldvalues, array $keyfields)
  • string $table: Table to update
  • array $fieldvalues: Associative array of field values to set
  • array $keyfields: Associative array of field values to match
upgrade (line 709)

Updates the content of the database between versions.

Implemented in child classes.

  • access: public
void upgrade (integer $old_version, [ $upgrade_path = ''])
  • integer $old_version: The old Version::DB_VERSION
  • $upgrade_path

Redefined in descendants as:

Documentation generated on Thu, 30 Oct 2008 20:31:08 +0100 by phpDocumentor 1.3.2