Inheritance diagram for DatabaseConnection:Public Member Functions | |
| connect ($connect_string, $db_user, $db_pass) | |
| disconnect () | |
| is_connected () | |
| in_transaction () | |
| table ($name) | |
| register_table ($name) | |
| set_fetch_mode ($mode) | |
| set_fetch_class ($class_name) | |
| exec ($query) | |
| query ($query, $args=array()) | |
| execute_procedure ($procedure, $args=array()) | |
| begin_transaction () | |
| rollback () | |
| commit () | |
| get_profiles () | |
| get_errors () | |
| has_errors () | |
| clear_errors () | |
| get_last_error () | |
| get_results ($query, $args=array()) | |
| get_row ($query, $args=array()) | |
| get_column ($query, $args=array()) | |
| get_value ($query, $args=array()) | |
| get_keyvalue ($query, $args=array()) | |
| insert ($table, $fieldvalues) | |
| exists ($table, $keyfieldvalues) | |
| update ($table, $fieldvalues, $keyfields) | |
| delete ($table, $keyfields) | |
| last_insert_id () | |
| dbdelta ($queries, $execute=true, $silent=true) | |
| upgrade_pre ($old_version) | |
| upgrade_post ($old_version) | |
| upgrade ($old_version, $upgrade_path= '') | |
| query_file ($file) | |
| sql_t ($query) | |
| filter_tables ($query) | |
| get_driver_name () | |
| get_driver_version () | |
| row_count () | |
| list_tables () | |
| quote ($string) | |
Static Public Member Functions | |
| static | ConnectionFactory ($connect_string) |
Protected Member Functions | |
| load_tables () | |
Protected Attributes | |
| $pdo = null | |
| $prefix = '' | |
Habari DatabaseConnection Class
Actual database connection.
Definition at line 12 of file databaseconnection.php.
| DatabaseConnection::begin_transaction | ( | ) |
Start a transaction against the RDBMS in order to wrap multiple statements in a safe ACID-compliant container
Definition at line 349 of file databaseconnection.php.
| DatabaseConnection::clear_errors | ( | ) |
Updates the last error pointer to simulate resetting the error array
Definition at line 427 of file databaseconnection.php.
| DatabaseConnection::commit | ( | ) |
Commit a currently running transaction
Definition at line 373 of file databaseconnection.php.
| DatabaseConnection::connect | ( | $ | connect_string, | |
| $ | db_user, | |||
| $ | db_pass | |||
| ) |
Connect to a database server
| string | $connect_string a PDO connection string | |
| string | $db_user the database user name | |
| string | $db_pass the database user password |
Reimplemented in MySQLConnection, PGSQLConnection, and SQLiteConnection.
Definition at line 113 of file databaseconnection.php.
| static DatabaseConnection::ConnectionFactory | ( | $ | connect_string | ) | [static] |
Returns the appropriate type of Connection class for the connect string passed or null on failure
| connection_string | a PDO connection string |
Definition at line 75 of file databaseconnection.php.
Referenced by DB::connect().
| DatabaseConnection::dbdelta | ( | $ | queries, | |
| $ | execute = true, |
|||
| $ | silent = true | |||
| ) |
Automatic diffing function, used for determining required database upgrades. Implemented in child classes.
Definition at line 691 of file databaseconnection.php.
| DatabaseConnection::delete | ( | $ | table, | |
| $ | keyfields | |||
| ) |
Deletes any record that matches the specific criteria
| string | Table to delete from | |
| array | Associative array of field values to match |
DB::delete( 'mytable', array( 'fieldname' => 'value' ) ); Definition at line 657 of file databaseconnection.php.
| DatabaseConnection::disconnect | ( | ) |
Disconnect from the database server.
Definition at line 126 of file databaseconnection.php.
| DatabaseConnection::exec | ( | $ | query | ) |
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.
| string | $query the query to run |
Definition at line 210 of file databaseconnection.php.
Referenced by SQLiteConnection::connect(), MySQLConnection::connect(), SQLiteConnection::dbdelta(), PGSQLConnection::dbdelta(), and MySQLConnection::dbdelta().
| DatabaseConnection::execute_procedure | ( | $ | procedure, | |
| $ | args = array() | |||
| ) |
Execute a stored procedure
| procedure | name of the stored procedure | |
| args | arguments for the procedure |
EVERYTHING... :) Implemented in child classes. Most RDBMS use ANSI-92 syntax,
Make sure it's MultiByte safe ( CALL procname ( param1, param2, ... ), so they return the call to here. Those that don't, handle the call individually
Reimplemented in SQLiteConnection.
Definition at line 305 of file databaseconnection.php.
| DatabaseConnection::exists | ( | $ | table, | |
| $ | keyfieldvalues | |||
| ) |
Checks for a record that matches the specific criteria
| string | Table to check | |
| array | Associative array of field values to match |
DB::exists( 'mytable', array( 'fieldname' => 'value' ) ); Definition at line 586 of file databaseconnection.php.
Referenced by update().
| DatabaseConnection::filter_tables | ( | $ | query | ) |
Replace braced table names with their prefixed counterparts
| string | $query The query with {braced} table names |
Definition at line 790 of file databaseconnection.php.
Referenced by MySQLConnection::dbdelta(), exec(), and query().
| DatabaseConnection::get_column | ( | $ | query, | |
| $ | args = array() | |||
| ) |
Returns all values for a column for a query
| string | The query to execute | |
| array | Arguments to pass for prepared statements |
$ary= DB::get_column( 'SELECT col1 FROM tablename WHERE foo= ?', array( 'fieldvalue' ) ); Definition at line 506 of file databaseconnection.php.
Referenced by SQLiteConnection::dbdelta(), PGSQLConnection::dbdelta(), and MySQLConnection::dbdelta().
| DatabaseConnection::get_errors | ( | ) |
Returns error data gathered from database connection
Definition at line 410 of file databaseconnection.php.
Referenced by SQLiteConnection::dbdelta(), PGSQLConnection::dbdelta(), and MySQLConnection::dbdelta().
| DatabaseConnection::get_keyvalue | ( | $ | query, | |
| $ | args = array() | |||
| ) |
Returns an associative array using the first returned column as the array key and the second as the array value
| string | The query to execute | |
| array | Arguments to pass for prepared statements |
$ary= $dbconnection->get_keyvalue( 'SELECT keyfield, valuefield FROM tablename'); Definition at line 542 of file databaseconnection.php.
| DatabaseConnection::get_last_error | ( | ) |
Returns only the last error info
Definition at line 436 of file databaseconnection.php.
| DatabaseConnection::get_profiles | ( | ) |
Returns query profiles
Definition at line 386 of file databaseconnection.php.
| DatabaseConnection::get_results | ( | $ | query, | |
| $ | args = array() | |||
| ) |
Execute a query and return the results as an array of objects
| query | the query to execute | |
| args | array of arguments to pass for prepared statements | |
| string | Optional class name for row result objects |
$ary= DB::get_results( 'SELECT * FROM tablename WHERE foo= ?', array( 'fieldvalue' ), 'extendedQueryRecord' ); Definition at line 450 of file databaseconnection.php.
Referenced by SQLiteConnection::dbdelta(), PGSQLConnection::dbdelta(), and MySQLConnection::dbdelta().
| DatabaseConnection::get_row | ( | $ | query, | |
| $ | args = array() | |||
| ) |
Returns a single row (the first in a multi-result set) object for a query
| string | The query to execute | |
| array | Arguments to pass for prepared statements | |
| string | Optional class name for row result object |
$obj= DB::get_row( 'SELECT * FROM tablename WHERE foo= ?', array( 'fieldvalue' ), 'extendedQueryRecord' ); Definition at line 477 of file databaseconnection.php.
Referenced by exists().
| DatabaseConnection::get_value | ( | $ | query, | |
| $ | args = array() | |||
| ) |
Return a single value from the database
| string | the query to execute | |
| array | Arguments to pass for prepared statements |
Definition at line 523 of file databaseconnection.php.
Referenced by SQLiteConnection::dbdelta().
| DatabaseConnection::has_errors | ( | ) |
Determines if there have been errors since the last clear_errors() call
Definition at line 419 of file databaseconnection.php.
| DatabaseConnection::in_transaction | ( | ) |
Check whether there is a transaction underway.
Definition at line 148 of file databaseconnection.php.
| DatabaseConnection::insert | ( | $ | table, | |
| $ | fieldvalues | |||
| ) |
Inserts into the specified table values associated to the key fields
| string | The table name | |
| array | An associative array of fields and values to insert |
DB::insert( 'mytable', array( 'fieldname' => 'value' ) ); Definition at line 564 of file databaseconnection.php.
Referenced by update().
| DatabaseConnection::is_connected | ( | ) |
Check whether there is an existing connection to a database.
Definition at line 138 of file databaseconnection.php.
| DatabaseConnection::last_insert_id | ( | ) |
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.
Definition at line 677 of file databaseconnection.php.
| DatabaseConnection::list_tables | ( | ) |
Returns a list of tables the DB currently knows about.
Definition at line 823 of file databaseconnection.php.
| DatabaseConnection::load_tables | ( | ) | [protected] |
Populate the table mapping.
Definition at line 88 of file databaseconnection.php.
Referenced by connect(), and register_table().
| DatabaseConnection::query | ( | $ | query, | |
| $ | args = array() | |||
| ) |
Execute a SQL statement.
| string | $query the SQL statement | |
| array | $args values for the bound parameters |
Definition at line 231 of file databaseconnection.php.
Referenced by SQLiteConnection::dbdelta(), delete(), get_column(), get_keyvalue(), get_results(), get_row(), get_value(), insert(), query_file(), and update().
| DatabaseConnection::query_file | ( | $ | file | ) |
Load a file containing queries, replace the prefix, execute all queries present
| string | $file The filename containing the queries |
Definition at line 752 of file databaseconnection.php.
Referenced by upgrade().
| DatabaseConnection::quote | ( | $ | string | ) |
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!
| string | $string The string to quote. |
Definition at line 836 of file databaseconnection.php.
| DatabaseConnection::register_table | ( | $ | name | ) |
| DatabaseConnection::rollback | ( | ) |
Rolls a currently running transaction back to the prexisting state, or, if the RDBMS supports it, whenever a savepoint was committed.
Definition at line 362 of file databaseconnection.php.
| DatabaseConnection::row_count | ( | ) |
Returns number of rows affected by the last DELETE, INSERT, or UPDATE
Definition at line 813 of file databaseconnection.php.
| DatabaseConnection::set_fetch_class | ( | $ | class_name | ) |
Sets the class to fetch, if fetch mode is PDO::FETCH_CLASS
| class_name | Name of class to create during fetch |
Definition at line 197 of file databaseconnection.php.
Referenced by get_results(), and get_row().
| DatabaseConnection::set_fetch_mode | ( | $ | mode | ) |
Sets the fetch mode for return calls from PDOStatement
| mode | One of the PDO::FETCH_MODE integers |
Definition at line 187 of file databaseconnection.php.
Referenced by get_results(), and get_row().
| DatabaseConnection::sql_t | ( | $ | query | ) |
Translates the query for the current database engine
| string | $query The query to translate for the current database engine | |
| array | $args Arguments to the query |
Reimplemented in MySQLConnection, PGSQLConnection, and SQLiteConnection.
Definition at line 779 of file databaseconnection.php.
Referenced by exec(), execute_procedure(), and query().
| DatabaseConnection::table | ( | $ | name | ) |
Get the full table name for the given table.
| string | $name name of the table |
Definition at line 159 of file databaseconnection.php.
| DatabaseConnection::update | ( | $ | table, | |
| $ | fieldvalues, | |||
| $ | keyfields | |||
| ) |
function update Updates any record that matches the specific criteria A new row is inserted if no existing record matches the criteria
| string | Table to update | |
| array | Associative array of field values to set | |
| array | Associative array of field values to match |
DB::update( 'mytable', array( 'fieldname' => 'newvalue' ), array( 'fieldname' => 'value' ) ); Definition at line 609 of file databaseconnection.php.
| DatabaseConnection::upgrade | ( | $ | old_version, | |
| $ | upgrade_path = '' | |||
| ) |
Updates the content of the database between versions. Implemented in child classes.
| integer | $old_version The old Version::DB_VERSION |
Definition at line 704 of file databaseconnection.php.
Referenced by SQLiteConnection::upgrade_post(), PGSQLConnection::upgrade_post(), MySQLConnection::upgrade_post(), SQLiteConnection::upgrade_pre(), PGSQLConnection::upgrade_pre(), and MySQLConnection::upgrade_pre().
1.7.1