DatabaseInterface
Joomla Framework Database Interface
| since |
1.0 |
|---|---|
| package |
Joomla Framework |
Methods
connect
Connects to the database if needed.
connect() : void
| since |
2.0.0 |
|---|---|
| throws |
|
connected
Determines if the connection to the server is active.
connected() : bool
| since |
2.0.0 |
|---|
Response
bool
createDatabase
Create a new database using information from $options object.
createDatabase(\stdClass options, bool utf = true) : bool|resource
| since |
2.0.0 |
|---|---|
| throws |
|
Arguments
- options
\stdClassObject used to pass user and database name to database driver. This object must have "db_name" and "db_user" set.- utf
boolTrue if the database supports the UTF-8 character set.
Response
bool|resource
decodeBinary
Replace special placeholder representing binary field with the original string.
decodeBinary(string|resource data) : string
| since |
1.7.0 |
|---|
Arguments
- data
string|resourceEncoded string or resource.
Response
stringThe original string.
disconnect
Disconnects the database.
disconnect() : void
| since |
2.0.0 |
|---|
dropTable
Drops a table from the database.
dropTable(string table, bool ifExists = true) : $this
| since |
2.0.0 |
|---|---|
| throws |
|
Arguments
- table
stringThe name of the database table to drop.- ifExists
boolOptionally specify that the table must exist before it is dropped.
Response
$this
escape
Escapes a string for usage in an SQL statement.
escape(string text, bool extra = false) : string
| since |
2.0.0 |
|---|
Arguments
- text
stringThe string to be escaped.- extra
boolOptional parameter to provide extra escaping.
Response
stringThe escaped string.
execute
Execute the SQL statement.
execute() : bool
| since |
2.0.0 |
|---|---|
| throws |
|
Response
bool
getAffectedRows
Get the number of affected rows for the previous executed SQL statement.
getAffectedRows() : int
| since |
2.0.0 |
|---|
Response
int
getCollation
Method to get the database collation in use by sampling a text field of a table in the database.
getCollation() : string|bool
| since |
2.0.0 |
|---|
Response
string|boolThe collation in use by the database or boolean false if not supported.
getConnection
Method that provides access to the underlying database connection.
getConnection() : resource
| since |
2.0.0 |
|---|
Response
resourceThe underlying database connection resource.
getConnectionCollation
Method to get the database connection collation, as reported by the driver.
getConnectionCollation() : string
If the connector doesn't support reporting this value please return an empty string.
| since |
2.0.0 |
|---|
Response
string
getConnectionEncryption
Method to get the database encryption details (cipher and protocol) in use.
getConnectionEncryption() : string
| since |
2.0.0 |
|---|
Response
stringThe database encryption details.
getCount
Get the total number of SQL statements executed by the database driver.
getCount() : int
| since |
2.0.0 |
|---|
Response
int
getDateFormat
Returns a PHP date() function compliant date format for the database driver.
getDateFormat() : string
| since |
2.0.0 |
|---|
Response
string
getMinimum
Get the minimum supported database version.
getMinimum() : string
| since |
2.0.0 |
|---|
Response
string
getName
Get the name of the database driver.
getName() : string
| since |
2.0.0 |
|---|
Response
string
getNullDate
Get the null or zero representation of a timestamp for the database driver.
getNullDate() : string
| since |
2.0.0 |
|---|
Response
string
getNumRows
Get the number of returned rows for the previous executed SQL statement.
getNumRows() : int
| since |
2.0.0 |
|---|
Response
int
getQuery
Get the current query object or a new QueryInterface object.
getQuery(bool new = false) : \Joomla\Database\QueryInterface
| since |
2.0.0 |
|---|---|
| throws |
|
Arguments
- new
boolFalse to return the current query object, True to return a new QueryInterface object.
Response
\Joomla\Database\QueryInterface
getServerType
Get the server family type.
getServerType() : string
| since |
2.0.0 |
|---|
Response
string
getTableColumns
Retrieves field information about the given tables.
getTableColumns(string table, bool typeOnly = true) : array
| since |
2.0.0 |
|---|---|
| throws |
|
Arguments
- table
stringThe name of the database table.- typeOnly
boolTrue (default) to only return field types.
Response
array
getTableKeys
Retrieves field information about the given tables.
getTableKeys(mixed tables) : array
| since |
2.0.0 |
|---|---|
| throws |
|
Arguments
- tables
mixedA table name or a list of table names.
Response
array
getTableList
Method to get an array of all tables in the database.
getTableList() : array
| since |
2.0.0 |
|---|---|
| throws |
|
Response
array
getVersion
Get the version of the database connector.
getVersion() : string
| since |
2.0.0 |
|---|
Response
string
hasUtfSupport
Determine whether or not the database engine supports UTF-8 character encoding.
hasUtfSupport() : bool
| since |
2.0.0 |
|---|
Response
boolTrue if the database engine supports UTF-8 character encoding.
insertid
Method to get the auto-incremented value from the last INSERT statement.
insertid() : mixed
| since |
2.0.0 |
|---|
Response
mixedThe value of the auto-increment field from the last inserted row.
insertObject
Inserts a row into a table based on an object's properties.
insertObject(string table, object &object, string key = null) : bool
| since |
2.0.0 |
|---|---|
| throws |
|
Arguments
- table
stringThe name of the database table to insert into.- object
objectA reference to an object whose public properties match the table fields.- key
stringThe name of the primary key. If provided the object property is updated.
Response
bool
isConnectionEncryptionSupported
Method to test if the database TLS connections encryption are supported.
isConnectionEncryptionSupported() : bool
| since |
2.0.0 |
|---|
Response
boolWhether the database supports TLS connections encryption.
isMinimumVersion
Method to check whether the installed database version is supported by the database driver
isMinimumVersion() : bool
| since |
2.0.0 |
|---|
Response
boolTrue if the database version is supported
isSupported
Test to see if the connector is available.
isSupported() : bool
| since |
1.0 |
|---|
Response
bool
loadAssoc
Method to get the first row of the result set from the database query as an associative array of ['field_name' => 'row_value'].
loadAssoc() : mixed
| since |
2.0.0 |
|---|---|
| throws |
|
Response
mixedThe return value or null if the query failed.
loadAssocList
Method to get an array of the result set rows from the database query where each row is an associative array of ['field_name' => 'row_value']. The array of rows can optionally be keyed by a field name, but defaults to a sequential numeric array.
loadAssocList(string key = null, string column = null) : mixed
NOTE: Choosing to key the result array by a non-unique field name can result in unwanted behavior and should be avoided.
| since |
2.0.0 |
|---|---|
| throws |
|
Arguments
- key
stringThe name of a field on which to key the result array.- column
stringAn optional column name. Instead of the whole row, only this column value will be in the result array.
Response
mixedThe return value or null if the query failed.
loadColumn
Method to get an array of values from the $offset field in each row of the result set from the database query.
loadColumn(int offset) : mixed
| since |
2.0.0 |
|---|---|
| throws |
|
Arguments
- offset
intThe row offset to use to build the result array.
Response
mixedThe return value or null if the query failed.
loadObject
Method to get the first row of the result set from the database query as an object.
loadObject(string class = stdClass::class) : mixed
| since |
2.0.0 |
|---|---|
| throws |
|
Arguments
- class
stringThe class name to use for the returned row object.
Response
mixedThe return value or null if the query failed.
loadObjectList
Method to get an array of the result set rows from the database query where each row is an object. The array of objects can optionally be keyed by a field name, but defaults to a sequential numeric array.
loadObjectList(string key = '', string class = stdClass::class) : mixed
NOTE: Choosing to key the result array by a non-unique field name can result in unwanted behavior and should be avoided.
| since |
2.0.0 |
|---|---|
| throws |
|
Arguments
- key
stringThe name of a field on which to key the result array.- class
stringThe class name to use for the returned row objects.
Response
mixedThe return value or null if the query failed.
loadResult
Method to get the first field of the first row of the result set from the database query.
loadResult() : mixed
| since |
2.0.0 |
|---|---|
| throws |
|
Response
mixedThe return value or null if the query failed.
loadRow
Method to get the first row of the result set from the database query as an array.
loadRow() : mixed
Columns are indexed numerically so the first column in the result set would be accessible via $row[0], etc.
| since |
2.0.0 |
|---|---|
| throws |
|
Response
mixedThe return value or null if the query failed.
loadRowList
Method to get an array of the result set rows from the database query where each row is an array. The array of objects can optionally be keyed by a field offset, but defaults to a sequential numeric array.
loadRowList(string key = null) : mixed
NOTE: Choosing to key the result array by a non-unique field can result in unwanted behavior and should be avoided.
| since |
2.0.0 |
|---|---|
| throws |
|
Arguments
- key
stringThe name of a field on which to key the result array.
Response
mixedThe return value or null if the query failed.
lockTable
Locks a table in the database.
lockTable(string tableName) : $this
| since |
2.0.0 |
|---|---|
| throws |
|
Arguments
- tableName
stringThe name of the table to unlock.
Response
$this
quote
Quotes and optionally escapes a string to database requirements for use in database queries.
quote(array|string text, bool escape = true) : string
| since |
2.0.0 |
|---|
Arguments
- text
array|stringA string or an array of strings to quote.- escape
boolTrue (default) to escape the string, false to leave it unchanged.
Response
string
quoteBinary
Quotes a binary string to database requirements for use in database queries.
quoteBinary(string data) : string
| since |
1.7.0 |
|---|
Arguments
- data
stringA binary string to quote.
Response
stringThe binary quoted input string.
quoteName
Wrap an SQL statement identifier name such as column, table or database names in quotes to prevent injection risks and reserved word conflicts.
quoteName(array|string name, array|string as = null) : array|string
| since |
2.0.0 |
|---|
Arguments
- name
array|stringThe identifier name to wrap in quotes, or an array of identifier names to wrap in quotes. Each type supports dot-notation name.- as
array|stringThe AS query part associated to $name. It can be string or array, in latter case it has to be same length of $name; if is null there will not be any AS part for string or array element.
Response
array|stringThe quote wrapped name, same type of $name.
renameTable
Renames a table in the database.
renameTable(string oldTable, string newTable, string backup = null, string prefix = null) : $this
| since |
2.0.0 |
|---|---|
| throws |
|
Arguments
- oldTable
stringThe name of the table to be renamed- newTable
stringThe new name for the table.- backup
stringTable prefix- prefix
stringFor the table - used to rename constraints in non-mysql databases
Response
$this
replacePrefix
This function replaces a string identifier with the configured table prefix.
replacePrefix(string sql, string prefix = '#__') : string
| since |
2.0.0 |
|---|
Arguments
- sql
stringThe SQL statement to prepare.- prefix
stringThe table prefix.
Response
stringThe processed SQL statement.
select
Select a database for use.
select(string database) : bool
| since |
2.0.0 |
|---|---|
| throws |
|
Arguments
- database
stringThe name of the database to select for use.
Response
bool
setQuery
Sets the SQL statement string for later execution.
setQuery(mixed query, int offset, int limit) : $this
| since |
2.0.0 |
|---|
Arguments
- query
mixedThe SQL statement to set either as a Query object or a string.- offset
intThe affected row offset to set. {@deprecated Use LimitableInterface::setLimit() instead}- limit
intThe maximum affected rows to set. {@deprecated Use LimitableInterface::setLimit() instead}
Response
$this
transactionCommit
Method to commit a transaction.
transactionCommit(bool toSavepoint = false) : void
| since |
2.0.0 |
|---|---|
| throws |
|
Arguments
- toSavepoint
boolIf true, commit to the last savepoint.
transactionRollback
Method to roll back a transaction.
transactionRollback(bool toSavepoint = false) : void
| since |
2.0.0 |
|---|---|
| throws |
|
Arguments
- toSavepoint
boolIf true, rollback to the last savepoint.
transactionStart
Method to initialize a transaction.
transactionStart(bool asSavepoint = false) : void
| since |
2.0.0 |
|---|---|
| throws |
|
Arguments
- asSavepoint
boolIf true and a transaction is already active, a savepoint will be created.
truncateTable
Method to truncate a table.
truncateTable(string table) : void
| since |
2.0.0 |
|---|---|
| throws |
|
Arguments
- table
stringThe table to truncate
unlockTables
Unlocks tables in the database.
unlockTables() : $this
| since |
2.0.0 |
|---|---|
| throws |
|
Response
$this
updateObject
Updates a row in a table based on an object's properties.
updateObject(string table, object &object, array|string key, bool nulls = false) : bool
| since |
2.0.0 |
|---|---|
| throws |
|
Arguments
- table
stringThe name of the database table to update.- object
objectA reference to an object whose public properties match the table fields.- key
array|stringThe name of the primary key.- nulls
boolTrue to update null fields or false to ignore them.
Response
bool