__destruct()
__toString()
cache()
caching()
commit_transaction()
connect()
connection()
count_last_query()
count_records()
datatype()
delete()
disconnect()
escape()
has_connection()
in_transaction()
insert()
instance()
list_columns()
list_indexes()
list_tables()
query()
quote()
quote_identifier()
quote_table()
rollback_transaction()
schema()
select()
set_charset()
start_transaction()
table_prefix()
update()
__construct()
_parse_type()
driver_commit()
driver_rollback()
driver_start_transaction()
release_savepoint()
rollback_savepoint()
set_savepoint()
$instances
$last_query
$_config
$_connection
$_identifier
$_in_transaction
$_instance
$_readonly
$_schema
$_transaction_depth
__destruct() : void
// Destroy the database instance unset(static::instances[(string) $db], $db);
[!!] Calling unset($db)
is not enough to destroy the database, as it
will still be stored in static::$instances
.
__toString() : string
echo (string) $db;
string
cache(array $result, string $sql, mixed $as_object) : \Fuel\Core\Database_Cached
$db->cache($result, $sql);
array
string
mixed
\Fuel\Core\Database_Cached
caching(bool $bool) : mixed
bool
whether to enable it [optional]
mixed
cache boolean when getting, current instance when setting.commit_transaction() : bool
$db->commit_transaction();
bool
connect() : void
This is called automatically when the first query is executed.
$db->connect();
\Fuel\Core\Database_Exception |
---|
connection() : resource
$db->connection()->lastInsertId('id');
resource
count_last_query() : integer
// Get the total number of records that match the last query $count = $db->count_last_query();
integer
count_records(mixed $table) : integer
// Get the total number of records in the "users" table $count = $db->count_records('users');
mixed
table name string or array(query, alias)
integer
datatype(string $type) : array
$db->datatype('char');
string
SQL data type
array
delete(string $table) : \Fuel\Core\Database_Query_Builder_Delete
// DELETE FROM users $query = $db->delete('users');
string
table to delete from
disconnect() : boolean
This is called automatically by [static::__destruct].
$db->disconnect();
boolean
escape(string $value) : string
$value = $db->escape('any string');
string
value to quote
string
has_connection() : bool
$db->has_connection()
bool
in_transaction() : bool
$db->in_transaction();
bool
insert(string $table, array $columns) : \Fuel\Core\Database_Query_Builder_Insert
// INSERT INTO users (id, username) $query = $db->insert('users', array('id', 'username'));
string
table to insert into
array
list of column names or array($column, $alias) or object
instance(string $name, array $config, bool $writable) : \Fuel\Core\Database_Connection
If configuration is not specified, it will be loaded from the database configuration file using the same group as the name.
// Load the default database
$db = static::instance();
// Create a custom configured instance
$db = static::instance('custom', $config);
string
instance name
array
configuration parameters
bool
when replication is enabled, whether to return the master connection
\FuelException |
---|
list_columns(string $table, string $like) : array
Optionally, a LIKE string can be used to search for specific fields.
// Get all columns from the "users" table
$columns = $db->list_columns('users');
// Get all name-related columns
$columns = $db->list_columns('users', '%name%');
string
table to get columns from
string
column to search for
array
list_indexes(string $table, string $like) : array
Optionally, a LIKE string can be used to search for specific indexes by name.
// Get all indexes from the "users" table
$indexes = $db->list_indexes('users');
// Get all name-related columns
$indexes = $db->list_indexes('users', '%name%');
string
table to get indexes from
string
index names to search for
array
list_tables(string $like) : array
Optionally, a LIKE string can be used to search for specific tables.
// Get all tables in the current database
$tables = $db->list_tables();
// Get all user-related tables
$tables = $db->list_tables('user%');
string
table to search for
array
query(integer $type, string $sql, mixed $as_object) : object: array: integer
// Make a SELECT query and use objects for results $db->query(static::SELECT, 'SELECT * FROM groups', true);
// Make a SELECT query and use "Model_User" for the results
$db->query(static::SELECT, 'SELECT * FROM users LIMIT 1', 'Model_User');
integer
static::SELECT, static::INSERT, etc
string
SQL query
mixed
result object class, true for stdClass, false for assoc array
object
Database_Result for SELECT queriesarray
list (insert id, row count) for INSERT queriesinteger
number of affected rows for all other queriesquote(mixed $value) : string
$db->quote(null); // 'null' $db->quote(10); // 10 $db->quote('fred'); // 'fred'
Objects passed to this function will be converted to strings.
[Database_Expression] objects will use the value of the expression.
[Database_Query] objects will be compiled and converted to a sub-query.
All other objects will be converted using the __toString
method.
uses | \Fuel\Core\static::escape |
---|
mixed
any value to quote
string
quote_identifier(mixed $value) : string
Adds the table prefix to the identifier if a table name is present.
$column = $db->quote_identifier($column);
You can also use SQL methods within identifiers.
// The value of "column" will be quoted
$column = $db->quote_identifier('COUNT("column")');
Objects passed to this function will be converted to strings.
[Database_Expression] objects will use the value of the expression.
[Database_Query] objects will be compiled and converted to a sub-query.
All other objects will be converted using the __toString
method.
uses | \Fuel\Core\static::table_prefix |
---|
mixed
any identifier
string
quote_table(mixed $value) : string
$table = $db->quote_table($table);
uses | \Fuel\Core\static::quote_identifier |
---|---|
uses | \Fuel\Core\static::table_prefix |
mixed
table name or array(table, alias)
string
rollback_transaction($rollback_all) : bool
Rollback to the current level uses SAVEPOINT, it does not work if current RDBMS does not support them. In this case system rollbacks all queries and closes the transaction
$db->rollback_transaction();
bool
schema(string $operation, array $params) : \Fuel\Core\Database_Query_Builder_Delete
// CREATE DATABASE database CHARACTER SET utf-8 DEFAULT utf-8 $query = $db->schema('create_database', array('database', 'utf-8'));
string
table to delete from
select(array $args) : \Fuel\Core\Database_Query_Builder_Select
Each argument will be
treated as a column. To generate a foo AS bar
alias, use an array.
// SELECT id, username
$query = $db->select('id', 'username');
// SELECT id AS user_id
$query = $db->select(array('id', 'user_id'));
mixed
column name or array($column, $alias) or object
set_charset(string $charset) : void
This is called automatically by [static::connect].
$db->set_charset('utf8');
string
character set name
\Fuel\Core\Database_Exception |
---|
start_transaction() : bool
$db->start_transaction();
bool
table_prefix(string $table) : string
$prefix = $db->table_prefix();
string
string
update(string $table) : \Fuel\Core\Database_Query_Builder_Update
// UPDATE users $query = $db->update('users');
string
table to update
__construct(string $name, array $config)
[!!] This method cannot be accessed directly, you must use [static::instance].
string
array
_parse_type(string $type) : array
// Returns: array('CHAR', '6') list($type, $length) = $db->_parse_type('CHAR(6)');
string
array
list containing the type and length, if anydriver_commit() : bool
bool
driver_rollback() : bool
bool
driver_start_transaction() : bool
bool
release_savepoint(string $name) : boolean
string
name of the savepoint
boolean
true - savepoint was set successfully;
false - failed to set savepoint;
null - RDBMS does not support savepointsrollback_savepoint(string $name) : boolean
string
name of the savepoint
boolean
true - savepoint was set successfully;
false - failed to set savepoint;
null - RDBMS does not support savepointsset_savepoint(string $name) : boolean
string
name of the savepoint
boolean
true - savepoint was set successfully;
false - failed to set savepoint;
null - RDBMS does not support savepoints$instances : array
$last_query : string
$_config : array
$_connection : resource
$_identifier : string
$_in_transaction : bool
$_instance : string
$_readonly : string
$_transaction_depth : int