DbalInterface
interface DbalInterface (View source)
Main interface for database interactions
Constants
FETCH_NUM |
|
FETCH_ASSOC |
|
Methods
Executes a query and returns the result
Executes a query and returns the result or false on error
Send multiple SQL queries to the database server and execute the first one
returns array with table names for given db
returns array of all tables in given db or dbs
this function expects unquoted names:
RIGHT: my_database
WRONG: my_database
WRONG: my_database
if $tbl_is_group is true, $table is used as filter for table names
returns array with databases containing extended infos about them
returns detailed array with all columns for given table in database, or all tables/databases
Returns description of a $column in given table
Returns descriptions of columns in given table
Returns all column names in given table
Returns indexes of a table
returns value of given mysql server variable
Sets new value for a variable if it is different from the current value
Function called just after a connection to the MySQL database server has been established. It sets the connection collation, and determines the version of MySQL which is running.
Sets collation connection for user link
returns a single value from the given result or query, if the query or the result has more than one row or field the first field of the first row is returned
Returns only the first row from the result or null if result is empty.
returns all rows in the resultset in one array
Get supported SQL compatibility modes
returns warnings for last query
gets the current user with host
Checks if current user is superuser
No description
No description
No description
Get the current user and host
Returns value for lower_case_table_names variable
selects given database
Prepare next result from multi_query
Returns a string representing the type of connection used
returns a string that represents the client library version
Returns last error message or an empty string if no errors occurred.
returns the number of rows returned by last query used with tryQuery as it accepts false
returns last inserted auto_increment id for given $link
returns the number of rows affected by last query
Returns properly quoted string for use in MySQL queries.
Returns properly escaped string for use in MySQL LIKE clauses.
Checks if this database server is running on Amazon RDS.
Gets SQL for killing a process.
returns collation of given db
returns default server collation from show variables
Server version as number
Server version
Server version comment
Whether connection is MySQL
Whether connection is MariaDB
Whether connection is Percona
Prepare an SQL statement for execution.
Details
ResultInterface
query(string $query, ConnectionType $connectionType = ConnectionType::User, bool $unbuffered = false, bool $cacheAffectedRows = true)
Executes a query and returns the result
ResultInterface|false
tryQuery(string $query, ConnectionType $connectionType = ConnectionType::User, bool $unbuffered = false, bool $cacheAffectedRows = true)
Executes a query and returns the result or false on error
bool
tryMultiQuery(string $multiQuery = '', ConnectionType $connectionType = ConnectionType::User)
Send multiple SQL queries to the database server and execute the first one
array
getTables(string $database, ConnectionType $connectionType = ConnectionType::User)
returns array with table names for given db
array
getTablesFull(string $database, string|array $table = '', bool $tableIsGroup = false, int $limitOffset = 0, bool|int $limitCount = false, string $sortBy = 'Name', string $sortOrder = 'ASC', string|null $tableType = null, ConnectionType $connectionType = ConnectionType::User)
returns array of all tables in given db or dbs
this function expects unquoted names:
RIGHT: my_database
WRONG: my_database
WRONG: my_database
if $tbl_is_group is true, $table is used as filter for table names
$dbi->getTablesFull('my_database');
$dbi->getTablesFull('my_database', 'my_table'));
$dbi->getTablesFull('my_database', 'my_tables_', true));
array
getDatabasesFull(string|null $database = null, bool $forceStats = false, ConnectionType $connectionType = ConnectionType::User, string $sortBy = 'SCHEMA_NAME', string $sortOrder = 'ASC', int $limitOffset = 0, bool|int $limitCount = false)
returns array with databases containing extended infos about them
array
getColumnsFull(string|null $database = null, string|null $table = null, string|null $column = null, ConnectionType $connectionType = ConnectionType::User)
returns detailed array with all columns for given table in database, or all tables/databases
Column|null
getColumn(string $database, string $table, string $column, bool $full = false, ConnectionType $connectionType = ConnectionType::User)
Returns description of a $column in given table
array
getColumns(string $database, string $table, bool $full = false, ConnectionType $connectionType = ConnectionType::User)
Returns descriptions of columns in given table
array
getColumnNames(string $database, string $table, ConnectionType $connectionType = ConnectionType::User)
Returns all column names in given table
array
getTableIndexes(string $database, string $table, ConnectionType $connectionType = ConnectionType::User)
Returns indexes of a table
false|string|null
getVariable(string $var, int $type = DatabaseInterface::GETVAR_SESSION, ConnectionType $connectionType = ConnectionType::User)
returns value of given mysql server variable
bool
setVariable(string $var, string $value, ConnectionType $connectionType = ConnectionType::User)
Sets new value for a variable if it is different from the current value
void
postConnect(Server $currentServer)
Function called just after a connection to the MySQL database server has been established. It sets the connection collation, and determines the version of MySQL which is running.
void
setCollation(string $collation)
Sets collation connection for user link
string|false|null
fetchValue(string $query, int|string $field = 0, ConnectionType $connectionType = ConnectionType::User)
returns a single value from the given result or query, if the query or the result has more than one row or field the first field of the first row is returned
$sql = 'SELECT `name` FROM `user` WHERE `id` = 123';
$user_name = $dbi->fetchValue($sql);
// produces
// $user_name = 'John Doe'
array|null
fetchSingleRow(string $query, string $type = DbalInterface::FETCH_ASSOC, ConnectionType $connectionType = ConnectionType::User)
Returns only the first row from the result or null if result is empty.
$sql = 'SELECT * FROM `user` WHERE `id` = 123';
$user = $dbi->fetchSingleRow($sql);
// produces
// $user = array('id' => 123, 'name' => 'John Doe')
array
fetchResult(string $query, string|int|array|null $key = null, string|int|null $value = null, ConnectionType $connectionType = ConnectionType::User)
returns all rows in the resultset in one array
$sql = 'SELECT * FROM `user`';
$users = $dbi->fetchResult($sql);
// produces
// $users[] = array('id' => 123, 'name' => 'John Doe')
$sql = 'SELECT `id`, `name` FROM `user`';
$users = $dbi->fetchResult($sql, 'id');
// produces
// $users['123'] = array('id' => 123, 'name' => 'John Doe')
$sql = 'SELECT `id`, `name` FROM `user`';
$users = $dbi->fetchResult($sql, 0);
// produces
// $users['123'] = array(0 => 123, 1 => 'John Doe')
$sql = 'SELECT `id`, `name` FROM `user`';
$users = $dbi->fetchResult($sql, 'id', 'name');
// or
$users = $dbi->fetchResult($sql, 0, 1);
// produces
// $users['123'] = 'John Doe'
$sql = 'SELECT `name` FROM `user`';
$users = $dbi->fetchResult($sql);
// produces
// $users[] = 'John Doe'
$sql = 'SELECT `group`, `name` FROM `user`'
$users = $dbi->fetchResult($sql, array('group', null), 'name');
// produces
// $users['admin'][] = 'John Doe'
$sql = 'SELECT `group`, `name` FROM `user`'
$users = $dbi->fetchResult($sql, array('group', 'name'), 'id');
// produces
// $users['admin']['John Doe'] = '123'
array
getCompatibilities()
Get supported SQL compatibility modes
array
getWarnings(ConnectionType $connectionType = ConnectionType::User)
returns warnings for last query
string
getCurrentUser()
gets the current user with host
bool
isSuperUser()
Checks if current user is superuser
bool
isGrantUser()
No description
bool
isCreateUser()
No description
bool
isConnected()
No description
array
getCurrentUserAndHost()
Get the current user and host
int
getLowerCaseNames()
Returns value for lower_case_table_names variable
Connection|null
connect(Server $currentServer, ConnectionType $connectionType, ConnectionType|null $target = null)
Connects to the database server.
bool
selectDb(DatabaseName $dbname, ConnectionType $connectionType = ConnectionType::User)
selects given database
ResultInterface|false
nextResult(ConnectionType $connectionType = ConnectionType::User)
Prepare next result from multi_query
string|bool
getHostInfo(ConnectionType $connectionType = ConnectionType::User)
Returns a string representing the type of connection used
string
getClientInfo()
returns a string that represents the client library version
string
getError(ConnectionType $connectionType = ConnectionType::User)
Returns last error message or an empty string if no errors occurred.
string|int
queryAndGetNumRows(string $query)
returns the number of rows returned by last query used with tryQuery as it accepts false
int
insertId(ConnectionType $connectionType = ConnectionType::User)
returns last inserted auto_increment id for given $link
int|string
affectedRows(ConnectionType $connectionType = ConnectionType::User, bool $getFromCache = true)
returns the number of rows affected by last query
array
getFieldsMeta(ResultInterface $result)
returns metainfo for fields in $result
string
quoteString(string $str, ConnectionType $connectionType = ConnectionType::User)
Returns properly quoted string for use in MySQL queries.
string
escapeMysqlWildcards(string $str)
Returns properly escaped string for use in MySQL LIKE clauses.
This method escapes only _, %, and /. It does not escape quotes or any other characters.
bool
isAmazonRds()
Checks if this database server is running on Amazon RDS.
string
getKillQuery(int $process)
Gets SQL for killing a process.
Table
getTable(string $dbName, string $tableName)
Get a table with database name and table name
string
getDbCollation(string $db)
returns collation of given db
string
getServerCollation()
returns default server collation from show variables
int
getVersion()
Server version as number
string
getVersionString()
Server version
string
getVersionComment()
Server version comment
bool
isMySql()
Whether connection is MySQL
bool
isMariaDB()
Whether connection is MariaDB
bool
isPercona()
Whether connection is Percona
Statement|null
prepare(string $query, ConnectionType $connectionType = ConnectionType::User)
Prepare an SQL statement for execution.