PHP 클래스 Habari\DatabaseConnection

Actual database connection.
파일 보기 프로젝트 열기: habari/system

보호된 프로퍼티들

프로퍼티 타입 설명
$pdo PDO
$prefix an array of query profiles

공개 메소드들

메소드 설명
ConnectionFactory ( string $connect_string ) : mixed Returns the appropriate type of Connection class for the connect string passed or null on failure
add_error ( array $error ) Adds an error to the internal collection
begin_transaction ( ) Start a transaction against the RDBMS in order to wrap multiple statements in a safe ACID-compliant container
clear_errors ( ) Updates the last error pointer to simulate resetting the error array
commit ( ) Commit a currently running transaction
connect ( string $connect_string, string $db_user, string $db_pass ) : boolean Connect to a database server
dbdelta ( $queries, $execute = true, $silent = true ) Automatic diffing function, used for determining required database upgrades.
delete ( string $table, array $keyfields ) : boolean Deletes any record that matches the specific criteria
disconnect ( ) : boolean Disconnect from the database server.
exec ( string $query ) : boolean Execute the given query on the database. Encapsulates PDO::exec.
execute_procedure ( string $procedure, array $args = [] ) : mixed Execute a stored procedure
exists ( string $table, array $keyfieldvalues ) : boolean Checks for a record that matches the specific criteria
filter_tables ( string $query ) : string Replace braced table names with their prefixed counterparts
get_column ( string $query, array $args = [] ) : array Returns all values for a column for a query
get_driver_name ( )
get_driver_version ( )
get_errors ( ) : array Returns error data gathered from database connection
get_keyvalue ( string $query, array $args = [] ) : array Returns an associative array using the first returned column as the array key and the second as the array value
get_last_error ( ) : array Returns only the last error info
get_profiles ( ) : array Returns query profiles
get_results ( string $query, array $args = [], string $class_name = '\Habari\QueryRecord' ) : array Execute a query and return the results as an array of objects
get_row ( string $query, array $args = [], string $class_name = '\Habari\QueryRecord' ) : object Returns a single row (the first in a multi-result set) object for a query
get_value ( string $query, array $args = [] ) : mixed Return a single value from the database
has_errors ( ) : boolean Determines if there have been errors since the last clear_errors() call
in_transaction ( ) : boolean Check whether there is a transaction underway.
insert ( string $table, array $fieldvalues ) : boolean Inserts into the specified table values associated to the key fields
is_connected ( ) : boolean Check whether there is an existing connection to a database.
last_insert_id ( ) : mixed 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.
list_tables ( ) : array Returns a list of tables the DB currently knows about.
query ( string $query, array $args = [] ) : boolean Execute a SQL statement.
query_file ( string $file ) : boolean Load a file containing queries, replace the prefix, execute all queries present
quote ( string $string ) : string Return a PDO-quoted string appropriate for the DB backend we're using.
register_table ( string $name ) 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
rollback ( ) Rolls a currently running transaction back to the prexisting state, or, if the RDBMS supports it, whenever a savepoint was committed.
row_count ( ) : integer Returns number of rows affected by the last DELETE, INSERT, or UPDATE
set_fetch_class ( string $class_name ) Sets the class to fetch, if fetch mode is PDO::FETCH_CLASS
set_fetch_mode ( integer $mode ) Sets the fetch mode for return calls from PDOStatement
sql_t ( string $query, array &$args ) : string Translates the query for the current database engine
table ( string $name ) : string Get the full table name for the given table.
update ( string $table, array $fieldvalues, array $keyfields ) : boolean function update Updates any record that matches the specific criteria A new row is inserted if no existing record matches the criteria
upgrade ( integer $old_version, string $upgrade_path = '' ) : boolean Updates the content of the database between versions.
upgrade_post ( $old_version )
upgrade_pre ( $old_version )

보호된 메소드들

메소드 설명
load_tables ( ) : void Populate the table mapping.

메소드 상세

ConnectionFactory() 공개 정적인 메소드

Returns the appropriate type of Connection class for the connect string passed or null on failure
public static ConnectionFactory ( string $connect_string ) : mixed
$connect_string string a PDO connection string
리턴 mixed returns appropriate DatabaseConnection child class instance or errors out if requiring the db class fails

add_error() 공개 메소드

Adds an error to the internal collection
public add_error ( array $error )
$error array An array with error components

begin_transaction() 공개 메소드

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

clear_errors() 공개 메소드

Updates the last error pointer to simulate resetting the error array
public clear_errors ( )

commit() 공개 메소드

Commit a currently running transaction
public commit ( )

connect() 공개 메소드

Connect to a database server
public connect ( string $connect_string, string $db_user, string $db_pass ) : boolean
$connect_string string a PDO connection string
$db_user string the database user name
$db_pass string the database user password
리턴 boolean true on success, false on error

dbdelta() 공개 메소드

Implemented in child classes.
public dbdelta ( $queries, $execute = true, $silent = true )

delete() 공개 메소드

Deletes any record that matches the specific criteria
public delete ( string $table, array $keyfields ) : boolean
$table string Table to delete from
$keyfields array Associative array of field values to match
리턴 boolean True on success, false if not DB::delete( 'mytable', array( 'fieldname' => 'value' ) );

disconnect() 공개 메소드

Disconnect from the database server.
public disconnect ( ) : boolean
리턴 boolean true

exec() 공개 메소드

WARNING: Make sure you don't call this with a SELECT statement. PDO will buffer the results and leave your cursor dangling.
public exec ( string $query ) : boolean
$query string the query to run
리턴 boolean true on success, false on error

execute_procedure() 공개 메소드

Execute a stored procedure
public execute_procedure ( string $procedure, array $args = [] ) : mixed
$procedure string name of the stored procedure
$args array arguments for the procedure
리턴 mixed whatever the procedure returns...

exists() 공개 메소드

Checks for a record that matches the specific criteria
public exists ( string $table, array $keyfieldvalues ) : boolean
$table string Table to check
$keyfieldvalues array Associative array of field values to match
리턴 boolean True if any matching record exists, false if not DB::exists( 'mytable', array( 'fieldname' => 'value' ) );

filter_tables() 공개 메소드

Replace braced table names with their prefixed counterparts
public filter_tables ( string $query ) : string
$query string The query with {braced} table names
리턴 string The translated query

get_column() 공개 메소드

Returns all values for a column for a query
public get_column ( string $query, array $args = [] ) : array
$query string The query to execute
$args array Arguments to pass for prepared statements
리턴 array An array containing the column data $ary= DB::get_column( 'SELECT col1 FROM tablename WHERE foo= ?', array( 'fieldvalue' ) );

get_driver_name() 공개 메소드

public get_driver_name ( )

get_driver_version() 공개 메소드

public get_driver_version ( )

get_errors() 공개 메소드

Returns error data gathered from database connection
public get_errors ( ) : array
리턴 array An array of error data

get_keyvalue() 공개 메소드

Returns an associative array using the first returned column as the array key and the second as the array value
public get_keyvalue ( string $query, array $args = [] ) : array
$query string The query to execute
$args array Arguments to pass for prepared statements
리턴 array An array containing the associative data $ary= $dbconnection->get_keyvalue( 'SELECT keyfield, valuefield FROM tablename');

get_last_error() 공개 메소드

Returns only the last error info
public get_last_error ( ) : array
리턴 array Data for the last error

get_profiles() 공개 메소드

Returns query profiles
public get_profiles ( ) : array
리턴 array an array of query profiles

get_results() 공개 메소드

Execute a query and return the results as an array of objects
public get_results ( string $query, array $args = [], string $class_name = '\Habari\QueryRecord' ) : array
$query string The query to execute
$args array An array of arguments to pass for prepared statements
$class_name string class name for row result objects
리턴 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' );

get_row() 공개 메소드

Returns a single row (the first in a multi-result set) object for a query
public get_row ( string $query, array $args = [], string $class_name = '\Habari\QueryRecord' ) : object
$query string The query to execute
$args array Arguments to pass for prepared statements
$class_name string Optional class name for row result object
리턴 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' );

get_value() 공개 메소드

Return a single value from the database
public get_value ( string $query, array $args = [] ) : mixed
$query string the query to execute
$args array Arguments to pass for prepared statements
리턴 mixed a single value ( int, string )

has_errors() 공개 메소드

Determines if there have been errors since the last clear_errors() call
public has_errors ( ) : boolean
리턴 boolean True if there were errors, false if not

in_transaction() 공개 메소드

Check whether there is a transaction underway.
public in_transaction ( ) : boolean
리턴 boolean

insert() 공개 메소드

Inserts into the specified table values associated to the key fields
public insert ( string $table, array $fieldvalues ) : boolean
$table string The table name
$fieldvalues array An associative array of fields and values to insert
리턴 boolean True on success, false if not DB::insert( 'mytable', array( 'fieldname' => 'value' ) );

is_connected() 공개 메소드

Check whether there is an existing connection to a database.
public is_connected ( ) : boolean
리턴 boolean

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.
또한 보기: http://us2.php.net/manual/en/function.pdo-lastinsertid.php
public last_insert_id ( ) : mixed
리턴 mixed The last sequence value ( RDBMS-dependent! )

list_tables() 공개 메소드

Returns a list of tables the DB currently knows about.
public list_tables ( ) : array
리턴 array The list of tables.

load_tables() 보호된 메소드

Populate the table mapping.
protected load_tables ( ) : void
리턴 void

query() 공개 메소드

Execute a SQL statement.
public query ( string $query, array $args = [] ) : boolean
$query string the SQL statement
$args array values for the bound parameters
리턴 boolean true on success, false on failure

query_file() 공개 메소드

Load a file containing queries, replace the prefix, execute all queries present
public query_file ( string $file ) : boolean
$file string The filename containing the queries
리턴 boolean True on successful execution of all queries

quote() 공개 메소드

If you're using this then there's 99+% probability you're building your queries the wrong way!
public quote ( string $string ) : string
$string string The string to quote.
리턴 string A DB-safe quoted string.

register_table() 공개 메소드

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
public register_table ( string $name )
$name string the table name

rollback() 공개 메소드

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

row_count() 공개 메소드

Returns number of rows affected by the last DELETE, INSERT, or UPDATE
public row_count ( ) : integer
리턴 integer The number of rows affected.

set_fetch_class() 공개 메소드

Sets the class to fetch, if fetch mode is PDO::FETCH_CLASS
public set_fetch_class ( string $class_name )
$class_name string Name of class to create during fetch

set_fetch_mode() 공개 메소드

Sets the fetch mode for return calls from PDOStatement
public set_fetch_mode ( integer $mode )
$mode integer One of the PDO::FETCH_MODE integers

sql_t() 공개 메소드

Translates the query for the current database engine
public sql_t ( string $query, array &$args ) : string
$query string The query to translate for the current database engine
$args array An array of SQL arguments
리턴 string The translated query

table() 공개 메소드

Get the full table name for the given table.
public table ( string $name ) : string
$name string name of the table
리턴 string the full table name, or the original value if the table was not found

update() 공개 메소드

function update Updates any record that matches the specific criteria A new row is inserted if no existing record matches the criteria
public update ( string $table, array $fieldvalues, array $keyfields ) : boolean
$table string Table to update
$fieldvalues array Associative array of field values to set
$keyfields array Associative array of field values to match
리턴 boolean True on success, false if not DB::update( 'mytable', array( 'fieldname' => 'newvalue' ), array( 'fieldname' => 'value' ) );

upgrade() 공개 메소드

Implemented in child classes.
public upgrade ( integer $old_version, string $upgrade_path = '' ) : boolean
$old_version integer The old Version::DB_VERSION
$upgrade_path string
리턴 boolean

upgrade_post() 공개 메소드

public upgrade_post ( $old_version )

upgrade_pre() 공개 메소드

public upgrade_pre ( $old_version )

프로퍼티 상세

$pdo 보호되어 있는 프로퍼티

protected PDO $pdo
리턴 PDO

$prefix 보호되어 있는 프로퍼티

an array of query profiles
protected $prefix