Static Public Member Functions | Static Protected Member Functions

DB Class Reference

Inheritance diagram for DB:
Collaboration diagram for DB:

List of all members.

Static Public Member Functions

static connect ()
static disconnect ()
static table ($name)
static register_table ($name)
static set_fetch_mode ($mode)
static set_fetch_class ($class_name)
static exec ($query)
static query ($query, $args=array())
static execute_procedure ($procedure, $args=array())
static begin_transaction ()
static rollback ()
static commit ()
static get_profiles ()
static get_errors ()
static has_errors ()
static clear_errors ()
static get_last_error ()
static get_results ($query, $args=array())
static get_row ($query, $args=array())
static get_column ($query, $args=array())
static get_value ($query, $args=array())
static get_keyvalue ($query, $args=array())
static insert ($table, $fieldvalues)
static exists ($table, $keyfieldvalues)
static update ($table, $fieldvalues, $keyfields)
static delete ($table, $keyfields)
static last_insert_id ()
static row_count ()
static dbdelta ($queries, $execute=true, $silent=true, $doinserts=false)
static upgrade ($old_version)
static upgrade_pre ($old_version)
static upgrade_post ($old_version)
static get_driver_name ()
static get_driver_version ()
static list_tables ()
static is_connected ()
static in_transaction ()
static quote ($string)

Static Protected Member Functions

static instance ()

Detailed Description

Habari DB Class

Singleton class for database connection and manipulation

Definition at line 13 of file db.php.


Member Function Documentation

static DB::begin_transaction (  )  [static]

Start a transaction against the RDBMS in order to wrap multiple statements in a safe ACID-compliant container

Definition at line 155 of file db.php.

Referenced by Vocabulary::add_term(), and Vocabulary::move_term().

static DB::clear_errors (  )  [static]

Updates the last error pointer to simulate resetting the error array

Definition at line 219 of file db.php.

static DB::commit (  )  [static]

Commit a currently running transaction

Definition at line 173 of file db.php.

Referenced by Vocabulary::add_term(), and Vocabulary::move_term().

static DB::connect (  )  [static]

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

Parameters:
(optional) connection_string a PDO connection string
(optional) db_user the database user name
(optional) db_pass the database user password
Returns:
bool

Definition at line 37 of file db.php.

Referenced by InstallHandler::ajax_check_mysql_credentials(), InstallHandler::ajax_check_pgsql_credentials(), InstallHandler::ajax_check_sqlite_credentials(), InstallHandler::check_mysql(), and InstallHandler::check_pgsql().

static DB::dbdelta ( queries,
execute = true,
silent = true,
doinserts = false 
) [static]

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

Parameters:
queries array of create table and insert statements which constitute a fresh install
(optional) execute should the queries be executed against the database or just simulated. default = true
(optional) silent silent running with no messages printed? default = true
Returns:
string translated SQL string

Definition at line 392 of file db.php.

Referenced by InstallHandler::upgrade_db().

static DB::delete ( table,
keyfields 
) [static]

Deletes any record that matches the specific criteria

Parameters:
string Table to delete from
array Associative array of field values to match
Returns:
boolean True on success, false if not DB::delete( 'mytable', array( 'fieldname' => 'value' ) );

Definition at line 355 of file db.php.

Referenced by InfoRecords::__unset(), ACL::revoke_group_token(), ACL::revoke_user_token(), and EventLog::unregister_type().

static DB::execute_procedure ( procedure,
args = array() 
) [static]

Executes a stored procedure against the database

Parameters:
procedure name of the stored procedure
args arguments for the procedure
Returns:
mixed whatever the procedure returns...
Todo:
EVERYTHING... :)

Definition at line 146 of file db.php.

static DB::exists ( table,
keyfieldvalues 
) [static]

Checks for a record that matches the specific criteria

Parameters:
string Table to check
array Associative array of field values to match
Returns:
boolean True if any matching record exists, false if not DB::exists( 'mytable', array( 'fieldname' => 'value' ) );

Definition at line 328 of file db.php.

Referenced by Vocabulary::add_object_type(), Term::associate(), Post::delete_post_type(), and EventLog::unregister_type().

static DB::get_column ( query,
args = array() 
) [static]

Returns all values for a column for a query

Parameters:
string The query to execute
array Arguments to pass for prepared statements
Returns:
array An array containing the column data $ary = DB::get_column( 'SELECT col1 FROM tablename WHERE foo = ?', array('fieldvalue') );

Definition at line 279 of file db.php.

Referenced by Vocabulary::delete(), Post::get_tokens(), ACL::grant_group(), UserGroup::load_member_cache(), Term::objects(), and ACL::user_tokens().

static DB::get_errors (  )  [static]

Returns error data gathered from database connection

Returns:
array An array of error data

Definition at line 202 of file db.php.

Referenced by Term::setslug().

static DB::get_keyvalue ( query,
args = array() 
) [static]

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

Parameters:
string The query to execute
array Arguments to pass for prepared statements
Returns:
array An array containing the associative data $ary= DB::get_keyvalue( 'SELECT keyfield, valuefield FROM tablename');

Definition at line 304 of file db.php.

Referenced by Term::object_types().

static DB::get_last_error (  )  [static]

Returns only the last error info

Returns:
array Data for the last error

Definition at line 228 of file db.php.

Referenced by AdminUsersHandler::post_users().

static DB::get_profiles (  )  [static]

Returns query profiles

Returns:
array an array of query profiles

Definition at line 183 of file db.php.

Referenced by Theme::theme_query_count(), and Theme::theme_query_time().

static DB::get_results ( query,
args = array() 
) [static]
static DB::get_row ( query,
args = array() 
) [static]

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

Parameters:
string The query to execute
array Arguments to pass for prepared statements
string Optional class name for row result object
Returns:
object A QueryRecord or an instance of the named class containing the row data $obj = DB::get_row( 'SELECT * FROM tablename WHERE foo = ?', array('fieldvalue'), 'extendedQueryRecord' );

Definition at line 260 of file db.php.

Referenced by AdminThemesHandler::ajax_delete_block(), CoreDashModules::filter_dash_module_latest_comments(), Vocabulary::get(), Term::get(), Comment::get(), Vocabulary::get_by_id(), UserGroup::get_by_id(), UserGroup::get_by_name(), AdminThemesHandler::get_configure_block(), CronTab::get_cronjob(), Vocabulary::get_term(), Term::parent(), Session::read(), and Term::setslug().

static DB::get_value ( query,
args = array() 
) [static]
static DB::has_errors (  )  [static]

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

Returns:
boolean True if there were errors, false if not

Definition at line 211 of file db.php.

static DB::in_transaction (  )  [static]

Check whether there is a transaction underway.

Returns:
boolean

Definition at line 452 of file db.php.

static DB::insert ( table,
fieldvalues 
) [static]

Inserts into the specified table values associated to the key fields

Parameters:
string The table name
array An associative array of fields and values to insert
Returns:
boolean True on success, false if not DB::insert( 'mytable', array( 'fieldname' => 'value' ) );

Definition at line 316 of file db.php.

static DB::instance (  )  [static, protected]
static DB::is_connected (  )  [static]

Check whether there is an existing connection to a database.

Returns:
boolean

Definition at line 442 of file db.php.

Referenced by Pluggable::upgrade().

static DB::last_insert_id (  )  [static]

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.

Returns:
mixed The last sequence value (RDBMS-dependent!)
See also:
http://us2.php.net/manual/en/function.pdo-lastinsertid.php

Definition at line 369 of file db.php.

Referenced by Vocabulary::insert(), UserGroup::insert(), Term::insert(), Post::insert(), LogEntry::insert(), Block::insert(), User::insert(), and Comment::insert().

static DB::list_tables (  )  [static]

Returns a list of tables the DB currently knows about.

Returns:
array The list of tables.

Definition at line 432 of file db.php.

static DB::query ( query,
args = array() 
) [static]
static DB::quote ( string  )  [static]

Return a PDO-quoted string appropriate for the DB backend we're using.

If you're using this then there's 99+% probability you're building your queries the wrong way!

Parameters:
string $string The string to quote.
Returns:
string A DB-safe quoted string.

Definition at line 465 of file db.php.

static DB::register_table ( name  )  [static]

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

Parameters:
name the table name

Definition at line 95 of file db.php.

static DB::rollback (  )  [static]

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

Definition at line 165 of file db.php.

Referenced by Vocabulary::add_term(), and Vocabulary::move_term().

static DB::row_count (  )  [static]

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

Returns:
int The number of rows affected.

Definition at line 379 of file db.php.

static DB::set_fetch_class ( class_name  )  [static]

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

Parameters:
class_name Name of class to create during fetch

Definition at line 115 of file db.php.

Referenced by EventLog::get(), Users::get(), Posts::get(), and Comments::get().

static DB::set_fetch_mode ( mode  )  [static]

Sets the fetch mode for return calls from PDOStatement

Parameters:
mode One of the PDO::FETCH_MODE integers

Definition at line 105 of file db.php.

Referenced by UserGroups::get(), EventLog::get(), Users::get(), Posts::get(), and Comments::get().

static DB::table ( name  )  [static]
static DB::update ( table,
fieldvalues,
keyfields 
) [static]

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

Parameters:
string Table to update
array Associative array of field values to set
array Associative array of field values to match
Returns:
boolean True on success, false if not DB::update( 'mytable', array( 'fieldname' => 'newvalue' ), array( 'fieldname' => 'value' ) );

Definition at line 343 of file db.php.

Referenced by Options::__set(), InfoRecords::commit(), ACL::grant_group(), ACL::grant_user(), Comments::moderate_these(), and Session::write().

static DB::upgrade ( old_version  )  [static]

Upgrade data in the database between database revisions

Parameters:
integer $old_version Optional version to upgrade to

Definition at line 402 of file db.php.


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