
This also defines the Database::connect() function that handles creating instances of the appropriate database handle for the requested database engine. /*
Definition at line 44 of file Database.php.
Public Member Functions | |
| Database () | |
| Legacy constructor to catch things that the abstract classification won't /*. | |
| & | connect ($db_name, $login, $password, $server='localhost', $port=NULL, $engine='mysql_detect', $options=array()) |
| This takes the place of a database constructor. | |
| smart_args ($args) | |
| I like how in perl you can pass variables into functions in lists or arrays, and they all show up to the function as one giant list. | |
| escape_array ($array) | |
| Calls $this->escape() on an array of strings. | |
| __destruct () | |
| Execute any destruct handler functions. | |
| register_global_name ($name) | |
| PHP 5.2 destroys the global variable name space before calling destruct handlers, so we'll need to keep track of the name if any destruct handlers might need to use it. | |
| register_destruct_handler ($func, $params=null) | |
| Because of changes in PHP that make it destroy objects before saving session data, this function was added to make sure that certain code (like session_write_close) gets executed before in time. | |
| error ($error='', $backtrace=true) | |
| Fill the error variables. | |
| & | query ($query) |
| Perform a database query and return a handle. | |
| query_row ($query) | |
| Returns a single row from the database and frees the result. | |
| query_assoc ($query) | |
| Returns a single assoc row from the database and frees the result. | |
| query_col ($query) | |
| Returns a single column from the database and frees the result. | |
| query_list ($query) | |
| Returns an array of all first colums returned from the specified query. | |
| query_list_array ($query) | |
| Returns an array of the results from the specified query. | |
| query_list_assoc ($query) | |
| Returns an array of the results from the specified query. | |
| query_keyed_list_array ($key, $query) | |
| Returns an array of the results from the specified query. | |
| query_keyed_list_assoc ($key, $query) | |
| Returns an array of the results from the specified query. | |
| query_num_rows ($query) | |
| Returns the row count from the query and frees the result. | |
| query_insert_id ($query) | |
| Returns the inserted id from the query and frees the result. | |
| insert_id () | |
| Wrapper for the last query statement's insert_id method. | |
| affected_rows () | |
| Wrapper for the last query statement's affected_rows method. | |
| enable_fatal_errors () | |
| This function and the next one control if the mysql_query throws a fatal error or not /*. | |
| disable_fatal_errors () | |
| This function disables the fatal error trigger code /*. | |
Public Attributes | |
| $dbh | |
| $error | |
| $err | |
| $errno | |
| $last_sh | |
| $fatal_errors = true | |
| $query_count = 0 | |
| $query_time = 0 | |
| $global_name = '' | |
| $destruct_handlers = array() | |
| Database::__destruct | ( | ) |
| Database::Database | ( | ) |
Legacy constructor to catch things that the abstract classification won't /*.
Definition at line 81 of file Database.php.
| & Database::connect | ( | $ | db_name, | |
| $ | login, | |||
| $ | password, | |||
| $ | server = 'localhost', |
|||
| $ | port = NULL, |
|||
| $ | engine = 'mysql_detect', |
|||
| $ | options = array() | |||
| ) |
This takes the place of a database constructor.
It should be called directly without an object as:
Database::connect(....)
This assumes that you are either using a class autoloader (php5) or have already require_once'd the appropriate database engine file (eg. Database_mysql.php).
| string | $db_name Name of the database we're connecting to | |
| string | $login Login name to use when connecting | |
| string | $password Password to use when connecting | |
| string | $server Database server to connect to (default: localhost) | |
| string | $port Port or socket address to connect to | |
| string | $engine Database engine to use (default: mysql_detect) | |
| array | $options Hash of var=>value pairs of server options for engines that support them |
Definition at line 106 of file Database.php.
Referenced by MythTV::__construct().
| Database::smart_args | ( | $ | args | ) |
I like how in perl you can pass variables into functions in lists or arrays, and they all show up to the function as one giant list.
This takes an array containing scalars and arrays of scalars, and returns one cleanarray of all values.
| mixed | $args Scalar or nested array to be "flattened" into a single array. |
Definition at line 141 of file Database.php.
| Database::escape_array | ( | $ | array | ) |
Calls $this->escape() on an array of strings.
Definition at line 164 of file Database.php.
| Database::register_global_name | ( | $ | name | ) |
PHP 5.2 destroys the global variable name space before calling destruct handlers, so we'll need to keep track of the name if any destruct handlers might need to use it.
| string | $name The global name this instance is registered as. /* |
Definition at line 199 of file Database.php.
| Database::register_destruct_handler | ( | $ | func, | |
| $ | params = null | |||
| ) |
Because of changes in PHP that make it destroy objects before saving session data, this function was added to make sure that certain code (like session_write_close) gets executed before in time.
Definition at line 214 of file Database.php.
| Database::error | ( | $ | error = '', |
|
| $ | backtrace = true | |||
| ) |
Fill the error variables.
| string | $error The string to set the error message to. Set to false if you want to wipe out the existing errors. | |
| bool | $backtrace Include a backtrace along with the error message. /* |
Definition at line 226 of file Database.php.
| & Database::query | ( | $ | query | ) |
Perform a database query and return a handle.
Usage:
$sh =& $db->query('SELECT * FROM foo WHERE x=? AND y=? AND z="bar\?"',
$x_value, $y_value);
| string | $query The query string | |
| mixed | $arg Query arguments to escape and insert at ? placeholders in $query | |
| mixed | ... Additional arguments |
Definition at line 255 of file Database.php.
| Database::query_row | ( | $ | query | ) |
Returns a single row from the database and frees the result.
| string | $query The query string | |
| mixed | $arg Query arguments to escape and insert at ? placeholders in $query | |
| mixed | ... Additional arguments |
Definition at line 279 of file Database.php.
| Database::query_assoc | ( | $ | query | ) |
Returns a single assoc row from the database and frees the result.
| string | $query The query string | |
| mixed | $arg Query arguments to escape and insert at ? placeholders in $query | |
| mixed | ... Additional arguments |
Definition at line 300 of file Database.php.
| Database::query_col | ( | $ | query | ) |
Returns a single column from the database and frees the result.
| string | $query The query string | |
| mixed | $arg Query arguments to escape and insert at ? placeholders in $query | |
| mixed | ... Additional arguments |
Definition at line 321 of file Database.php.
| Database::query_list | ( | $ | query | ) |
Returns an array of all first colums returned from the specified query.
| string | $query The query string | |
| mixed | $arg Query arguments to escape and insert at ? placeholders in $query | |
| mixed | ... Additional arguments |
Definition at line 342 of file Database.php.
| Database::query_list_array | ( | $ | query | ) |
Returns an array of the results from the specified query.
Each result is stored in an array.
| string | $query The query string | |
| mixed | $arg Query arguments to escape and insert at ? placeholders in $query | |
| mixed | ... Additional arguments |
Definition at line 367 of file Database.php.
| Database::query_list_assoc | ( | $ | query | ) |
Returns an array of the results from the specified query.
Each result is stored in an assoc.
| string | $query The query string | |
| mixed | $arg Query arguments to escape and insert at ? placeholders in $query | |
| mixed | ... Additional arguments |
Definition at line 392 of file Database.php.
| Database::query_keyed_list_array | ( | $ | key, | |
| $ | query | |||
| ) |
Returns an array of the results from the specified query.
Each result is stored in an array. The array returned will be indexed by the value of the column specified by $key.
| string | $key Column to use as the returned list's key | |
| string | $query The query string | |
| mixed | $arg Query arguments to escape and insert at ? placeholders in $query | |
| mixed | ... Additional arguments |
Definition at line 419 of file Database.php.
| Database::query_keyed_list_assoc | ( | $ | key, | |
| $ | query | |||
| ) |
Returns an array of the results from the specified query.
Each result is stored in an assoc. The array returned will be indexed by the value of the column specified by $key.
| string | $key Column to use as the returned list's key | |
| string | $query The query string | |
| mixed | $arg Query arguments to escape and insert at ? placeholders in $query | |
| mixed | ... Additional arguments |
Definition at line 446 of file Database.php.
| Database::query_num_rows | ( | $ | query | ) |
Returns the row count from the query and frees the result.
| string | $query The query string | |
| mixed | $arg Query arguments to escape and insert at ? placeholders in $query | |
| mixed | ... Additional arguments |
Definition at line 470 of file Database.php.
| Database::query_insert_id | ( | $ | query | ) |
Returns the inserted id from the query and frees the result.
| string | $query The query string | |
| mixed | $arg Query arguments to escape and insert at ? placeholders in $query | |
| mixed | ... Additional arguments |
Definition at line 491 of file Database.php.
| Database::insert_id | ( | ) |
Wrapper for the last query statement's insert_id method.
Definition at line 507 of file Database.php.
| Database::affected_rows | ( | ) |
Wrapper for the last query statement's affected_rows method.
Definition at line 515 of file Database.php.
| Database::enable_fatal_errors | ( | ) |
This function and the next one control if the mysql_query throws a fatal error or not /*.
Definition at line 522 of file Database.php.
| Database::disable_fatal_errors | ( | ) |
This function disables the fatal error trigger code /*.
Definition at line 529 of file Database.php.
| Database::$dbh |
Definition at line 47 of file Database.php.
| Database::$error |
Definition at line 50 of file Database.php.
| Database::$err |
Definition at line 53 of file Database.php.
| Database::$errno |
Definition at line 56 of file Database.php.
| Database::$last_sh |
Definition at line 59 of file Database.php.
| Database::$fatal_errors = true |
Definition at line 62 of file Database.php.
| Database::$query_count = 0 |
Definition at line 65 of file Database.php.
| Database::$query_time = 0 |
Definition at line 68 of file Database.php.
| Database::$global_name = '' |
Definition at line 71 of file Database.php.
| Database::$destruct_handlers = array() |
Definition at line 74 of file Database.php.
1.5.5