Class DB

Description

Habari DB Class

Located in /system/classes/db.php (line 9)

Singleton
   |
   --DB
Method Summary
static void begin_transaction ()
static void clear_errors ()
static void commit ()
static bool connect ((optional) 0, (optional) 1, (optional) 2)
static string dbdelta (queries $queries, [(optional) $execute = true], [(optional) $silent = true], [ $doinserts = false])
static boolean delete (string $table, array $keyfields)
static void disconnect ()
static void exec ( $query)
static mixed execute_procedure (procedure $procedure, [args $args = array()])
static boolean exists (string $table, array $keyfieldvalues)
static array get_column (string $query, [array $args = array()])
static void get_driver_name ()
static array get_errors ()
static array get_keyvalue (string $query, [array $args = array()])
static array get_last_error ()
static array get_profiles ()
static array get_results (query $query, [args $args = array()], string 2)
static object A get_row (string $query, [array $args = array()], string 2)
static mixed get_value (string $query, [array $args = array()])
static boolean has_errors ()
static boolean insert (string $table, array $fieldvalues)
static void instance ()
static boolean in_transaction ()
static boolean is_connected ()
static mixed last_insert_id ()
static array list_tables ()
static bool query (query $query, [args $args = array()], class_name 2)
static void register_table (name $name)
static void rollback ()
static int row_count ()
static void set_fetch_class (class_name $class_name)
static void set_fetch_mode (mode $mode)
static void table (table $name)
static boolean update (string $table, array $fieldvalues, array $keyfields)
static void upgrade (integer $old_version)
Methods
static method begin_transaction (line 151)

Start a transaction against the RDBMS in order to wrap multiple

statements in a safe ACID-compliant container

  • access: public
static void begin_transaction ()
static method clear_errors (line 214)

Updates the last error pointer to simulate resetting the error array

  • access: public
static void clear_errors ()
static method commit (line 169)

Commit a currently running transaction

  • access: public
static void commit ()
static method connect (line 33)

Connects to the database server. If no arguments are supplied, then the connection is attempted for the database authentication variables in config.php.

  • access: public
static bool connect ((optional) 0, (optional) 1, (optional) 2)
  • (optional) 0: connection_string a PDO connection string
  • (optional) 1: db_user the database user name
  • (optional) 2: db_pass the database user password
static method dbdelta (line 387)

Automatic datbase diffing function, used for determining required database upgrades.

  • return: translated SQL string
  • access: public
static string dbdelta (queries $queries, [(optional) $execute = true], [(optional) $silent = true], [ $doinserts = false])
  • queries $queries: array of create table and insert statements which constitute a fresh install
  • (optional) $execute: execute should the queries be executed against the database or just simulated. default = true
  • (optional) $silent: silent silent running with no messages printed? default = true
  • $doinserts
static method delete (line 350)

Deletes any record that matches the specific criteria

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

Executes a stored procedure against the database

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

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
static boolean exists (string $table, array $keyfieldvalues)
  • string $table: Table to check
  • array $keyfieldvalues: Associative array of field values to match
static method get_column (line 274)

Returns all values for a column for a query

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

Returns error data gathered from database connection

  • return: An array of error data
  • access: public
static array get_errors ()
static method get_keyvalue (line 299)

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. $aryDB::get_keyvalue'SELECT keyfield, valuefield FROM tablename');
  • access: public
static array get_keyvalue (string $query, [array $args = array()])
  • string $query: The query to execute
  • array $args: Arguments to pass for prepared statements
static method get_last_error (line 223)

Returns only the last error info

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

Returns query profiles

  • return: an array of query profiles
  • access: public
static array get_profiles ()
static method get_results (line 236)

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. $ary DB::get_results'SELECT * FROM tablename WHERE foo = ?'array('fieldvalue')'extendedQueryRecord' );
  • access: public
static 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
static method get_row (line 255)

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. $obj DB::get_row'SELECT * FROM tablename WHERE foo = ?'array('fieldvalue')'extendedQueryRecord' );
  • access: public
static 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
static method get_value (line 286)

Return a single value from the database

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

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

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

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
static boolean insert (string $table, array $fieldvalues)
  • string $table: The table name
  • array $fieldvalues: An associative array of fields and values to insert
static method instance (line 18)

Enables singleton working properly

static void instance ()

Redefinition of:
Singleton::instance()
Declarations that extend this method must have the same signature (arguments and returned types) to pass E_STRICT
static method in_transaction (line 432)

Check whether there is a transaction underway.

  • access: public
static boolean in_transaction ()
static method is_connected (line 422)

Check whether there is an existing connection to a database.

  • access: public
static boolean is_connected ()
static method last_insert_id (line 364)

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.

static mixed last_insert_id ()
static method list_tables (line 412)

Returns a list of tables the DB currently knows about.

  • return: The list of tables.
  • access: public
static array list_tables ()
static method query (line 128)

Queries the database for a given SQL command.

  • access: public
static bool query (query $query, [args $args = array()], class_name 2)
  • class_name 2: (optional) name of class name to wrangle returned data to
  • query $query: the SQL query text
  • args $args: array of values to use for placeholder replacement
static method register_table (line 91)

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
static void register_table (name $name)
  • name $name: the table name
static method rollback (line 161)

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

  • access: public
static void rollback ()
static method row_count (line 374)

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

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

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

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

Sets the fetch mode for return calls from PDOStatement

  • access: public
static void set_fetch_mode (mode $mode)
  • mode $mode: One of the PDO::FETCH_MODE integers
static method table (line 79)

Helper function to naturally return table names

  • access: public
static void table (table $name)
  • table $name: name of the table
static method update (line 338)

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
static 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
static method upgrade (line 397)

Upgrade data in the database between database revisions

  • access: public
static void upgrade (integer $old_version)
  • integer $old_version: Optional version to upgrade to

Inherited Methods

Inherited From Singleton

Singleton::__construct()
Singleton::getInstanceOf()
Singleton::instance()

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