Database connection class.
Database connection class.
This class is used to represent a database connection. It support multiple backends.
This class provides a get_instance convenience method that eases development with just one database connection (as is the case with almost all applications).
static get_instance($type=null, $settings=null) [static] ¶Obtain a database instance.
This method is modeled after the singleton design pattern, but you will need to initialize it with the connection settings. The first call to this method will initialize the database with the provided settings. Subsequent files return a reference to the database instance (and paramaters are ignored).
$typeThe type of database to be used.
$settingsAn associative array of connection settings.
setup($settings) ¶Prepares the database layer for deferred connection.
$settingsAssociative array of connection settings.
connect($settings=null) ¶Connects to the database using the specified connection settings.
$settingsAn associative array of connection settings. Set the debug and debug_print keys to true if you want to debug your queries.
disconnect() ¶Disconnects from the database.
Not calling this method is harmless for most database backends.
prepare($sql) ¶Prepares a query for execution.
$sqlThe SQL query to be prepared. Use ?fieldtype? strings.
A new PreparedQuery instance that can be executed.
prepare_execute_fetch_all($sql, $params=null) ¶Convenience method to quickly execute a single query and fetch all resulting rows from the result set.
If you want to use a query multiple times, you should obtain a PreparedQuery object by calling the prepare() method, execute it and operate on the ResultSet object.
$sqlThe SQL query to execute. Placeholders (e.g. ?int?) should be used.
$paramsZero or more parameters to be filled in in the $query. The number of parameters should match the number of placeholders in $query
prepare_execute_fetch($sql, $params=null) ¶Convenience method to quickly execute a single query and fetch one resulting row from the result set.
See DB::prepare_execute_fetch_all for more information.
$sqlThe SQL query to execute.
$paramsZero or more parameters to be filled in in the $query.
prepare_execute($sql, $params=null) ¶Convenience method to quickly execute a single query.
No results are retrieved. This method is pretty useless for SELECT queries, the number of affected rows is returned instead of result rows. See DB::prepare_execute_fetch_all for more information.
$sqlThe SQL query to execute.
$paramsZero or more parameters to be filled in in the $query.
The number of rows affected by the query. This only works for queries that operate on a number of rows, i.e. INSERT, UPDATE, REPLACE, and DELETE queries. For other query types null is returned.
$databasename [private] ¶Current database name.
$connected [private] ¶Boolean indication the connection status.
$last_query [private] ¶Last query executed.
$num_queries_executed [private] ¶Counter for the number of queries executed.
$debug_print [private] ¶Print queries before execution.
$queries_executed [private] ¶List of executed queries (only used if debugging is on).