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(), $class_name= '\Habari\QueryRecord')
static get_row ($query, $args=array(), $class_name= '\Habari\QueryRecord')
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 15 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 169 of file db.php.

Referenced by WPImport::action_auth_ajax_wp_import_comments(), WPImport::action_auth_ajax_wp_import_posts(), WPImport::action_auth_ajax_wp_import_users(), 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 233 of file db.php.

static DB::commit (  )  [static]
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 43 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:
array $queries array of create table and insert statements which constitute a fresh install
bool $execute (optional) should the queries be executed against the database or just simulated. default = true
bool $silent (optional) silent running with no messages printed? default = true
bool $doinserts
Returns:
string translated SQL string

Definition at line 395 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 Table to delete from
array $keyfields Associative array of field values to match
Returns:
boolean True on success, false if not DB::delete( 'mytable', array( 'fieldname' => 'value' ) );

Definition at line 357 of file db.php.

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

static DB::exec ( query  )  [static]

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.

Parameters:
string $query the query to run
Returns:
boolean true on success, false on error

Definition at line 135 of file db.php.

Referenced by Comment::remove_status(), and Comment::remove_type().

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

Executes a stored procedure against the database

Parameters:
string $procedure Name of the stored procedure
array $args Arguments for the procedure
Returns:
mixed whatever the procedure returns...
Todo:
EVERYTHING... :)

Definition at line 160 of file db.php.

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

Checks for a record that matches the specific criteria

Parameters:
string $table Table to check
array $keyfieldvalues 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 330 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 $query The query to execute
array $args 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 281 of file db.php.

Referenced by WPImport::action_auth_ajax_wp_import_comments(), WPImport::action_auth_ajax_wp_import_posts(), Query::column(), Vocabulary::delete(), Post::get_tokens(), ACL::grant_group(), UserGroup::load_member_cache(), Term::objects(), and ACL::user_tokens().

static DB::get_driver_name (  )  [static]
Returns:
mixed

Definition at line 430 of file db.php.

Referenced by Theme::filter_provided(), Pluggable::get_db_schema(), and AdminHandler::get_sysinfo().

static DB::get_driver_version (  )  [static]
Returns:
mixed

Definition at line 438 of file db.php.

Referenced by AdminHandler::get_sysinfo().

static DB::get_errors (  )  [static]

Returns error data gathered from database connection

Returns:
array An array of error data

Definition at line 216 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 $query The query to execute
array $args 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 306 of file db.php.

Referenced by Query::keyvalue(), Comment::list_comment_statuses(), Comment::list_comment_types(), and Post::list_revisions().

static DB::get_last_error (  )  [static]

Returns only the last error info

Returns:
array Data for the last error

Definition at line 242 of file db.php.

Referenced by AdminUsersHandler::do_add_user().

static DB::get_profiles (  )  [static]

Returns query profiles

Returns:
array an array of query profiles

Definition at line 197 of file db.php.

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

static DB::get_results ( query,
args = array(),
class_name = '\Habari\QueryRecord' 
) [static]

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

Parameters:
string $query the query to execute
array $args array of arguments to pass for prepared statements
null|string $class_name The name of the class name to return results as
Returns:
array An array of QueryRecord or the named class each containing the row data $ary = DB::get_results( 'SELECT * FROM tablename WHERE foo = ?', array('fieldvalue'), 'extendedQueryRecord' );

Definition at line 255 of file db.php.

Referenced by UserGroup::__get(), InfoRecords::_load(), CronHandler::act_poll_cron(), WPImport::action_auth_ajax_wp_import_comments(), WPImport::action_auth_ajax_wp_import_posts(), CoreDashModules::action_block_content_latest_comments(), Menus::action_plugin_deactivation(), AdminThemesHandler::ajax_add_block(), AdminThemesHandler::ajax_save_areas(), ACL::all_tokens(), Term::ancestors(), Term::children(), Term::descendants(), RewriteRules::get_active(), Options::get_all_options(), Theme::get_blocks(), Tags::get_by_frequency(), Post::get_revision_data(), Vocabulary::get_root_terms(), Theme::get_scopes(), Vocabulary::get_search(), AdminThemesHandler::get_themes(), Post::list_active_post_types(), Post::list_all_post_types(), LogEntry::list_logentry_types(), Post::list_post_statuses(), UserGroup::load_permissions_cache(), Term::not_ancestors(), Term::not_descendants(), Term::object_types(), AdminThemesHandler::prepare_block_list(), Query::results(), CronHandler::run_cron(), Vocabulary::search_term(), Charcoal::theme_show_tags(), and ACL::user_tokens().

static DB::get_row ( query,
args = array(),
class_name = '\Habari\QueryRecord' 
) [static]

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

Parameters:
string $query The query to execute
array $args Arguments to pass for prepared statements
string $class_name 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 268 of file db.php.

Referenced by AdminDashboardHandler::ajax_dashboard(), AdminThemesHandler::ajax_delete_block(), Term::get(), Comment::get(), UserGroup::get_by_id(), UserGroup::get_by_name(), CronTab::get_cronjob(), Vocabulary::get_term(), Term::parent(), Session::read(), Query::row(), 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 225 of file db.php.

static DB::in_transaction (  )  [static]

Check whether there is a transaction underway.

Returns:
boolean

Definition at line 468 of file db.php.

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

Inserts into the specified table values associated to the key fields

Parameters:
string $table The table name
array $fieldvalues 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 318 of file db.php.

Referenced by QueryRecord::insertRecord().

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 458 of file db.php.

Referenced by Error::error_handler(), Options::get_all_options(), and 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 371 of file db.php.

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

static DB::list_tables (  )  [static]

Returns a list of tables the DB currently knows about.

Returns:
array The list of tables.

Definition at line 448 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 481 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:
string $name The table name

Definition at line 102 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 179 of file db.php.

Referenced by WPImport::action_auth_ajax_wp_import_comments(), WPImport::action_auth_ajax_wp_import_posts(), WPImport::action_auth_ajax_wp_import_users(), 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 381 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:
string $class_name Name of class to create during fetch

Definition at line 122 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:
integer $mode One of the PDO::FETCH_MODE integers

Definition at line 112 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 Table to update
array $fieldvalues Associative array of field values to set
array $keyfields 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 345 of file db.php.

Referenced by Options::__set(), InfoRecords::commit(), ACL::grant_group(), ACL::grant_user(), QueryRecord::updateRecord(), 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
Returns:
bool

Definition at line 406 of file db.php.

static DB::upgrade_post ( old_version  )  [static]
Parameters:
$old_version 

Definition at line 422 of file db.php.

Referenced by InstallHandler::upgrade_db().

static DB::upgrade_pre ( old_version  )  [static]
Parameters:
$old_version 

Definition at line 414 of file db.php.

Referenced by InstallHandler::upgrade_db().


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