DatabaseInterface

Joomla Framework Database Interface

since

1.0

package

Joomla Framework

Methods

connect

Connects to the database if needed.

connect() : 
since

2.0.0

throws

RuntimeException

Response

void

connected

Determines if the connection to the server is active.

connected() : 
since

2.0.0

Response

bool

createDatabase

Create a new database using information from $options object.

createDatabase(\stdClass options,  utf = true) : bool|resource
since

2.0.0

throws

RuntimeException

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

createQuery

Create a new DatabaseQuery object.

createQuery() : \Joomla\Database\QueryInterface
since

4.0.0

Response

QueryInterface

decodeBinary

Replace special placeholder representing binary field with the original string.

decodeBinary(string|resource data) : 
since

1.7.0

Arguments

data

string|resourceEncoded string or resource.

Response

stringThe original string.

disconnect

Disconnects the database.

disconnect() : 
since

2.0.0

Response

void

dropTable

Drops a table from the database.

dropTable( table,  ifExists = true) : 
since

2.0.0

throws

RuntimeException

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( text,  extra = false) : 
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() : 
since

2.0.0

throws

RuntimeException

Response

bool

getAffectedRows

Get the number of affected rows for the previous executed SQL statement.

getAffectedRows() : 
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() : 
since

2.0.0

Response

resourceThe underlying database connection resource.

getConnectionCollation

Method to get the database connection collation, as reported by the driver.

getConnectionCollation() : 

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() : 
since

2.0.0

Response

stringThe database encryption details.

getCount

Get the total number of SQL statements executed by the database driver.

getCount() : 
since

2.0.0

Response

int

getDateFormat

Returns a PHP date() function compliant date format for the database driver.

getDateFormat() : 
since

2.0.0

Response

string

getMinimum

Get the minimum supported database version.

getMinimum() : 
since

2.0.0

Response

string

getName

Get the name of the database driver.

getName() : 
since

2.0.0

Response

string

getNullDate

Get the null or zero representation of a timestamp for the database driver.

getNullDate() : 
since

2.0.0

Response

string

getNumRows

Get the number of returned rows for the previous executed SQL statement.

getNumRows() : 
since

2.0.0

Response

int

getPrefix

Get the common table prefix for the database driver.

getPrefix() : 
since

3.0

Response

stringThe common database table prefix.

getQuery

Get the current query object. (Deprecated: Or a new QueryInterface object).

getQuery( new = false) : \Joomla\Database\QueryInterface
since

2.0.0

throws

RuntimeException

Arguments

new

boolFalse to return the current query object, True to return a new DatabaseQuery object. The $new parameter is deprecated in 2.2 and will be removed in 5.0, use createQuery() instead.

Response

QueryInterface

getServerType

Get the server family type.

getServerType() : 
since

2.0.0

Response

string

getTableColumns

Retrieves field information about the given tables.

getTableColumns( table,  typeOnly = true) : mixed||string|int
since

2.0.0

throws

RuntimeException

Arguments

table

stringThe name of the database table.

typeOnly

boolTrue (default) to only return field types.

Response

array<string|int, mixed>

getTableKeys

Retrieves field information about the given tables.

getTableKeys( tables) : mixed||string|int
since

2.0.0

throws

RuntimeException

Arguments

tables

mixedA table name or a list of table names.

Response

array<string|int, mixed>

getTableList

Method to get an array of all tables in the database.

getTableList() : mixed||string|int
since

2.0.0

throws

RuntimeException

Response

array<string|int, mixed>

getVersion

Get the version of the database connector.

getVersion() : 
since

2.0.0

Response

string

hasUtfSupport

Determine whether or not the database engine supports UTF-8 character encoding.

hasUtfSupport() : 
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() : 
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( table,  &object,  key = null) : 
since

2.0.0

throws

RuntimeException

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() : 
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() : 
since

2.0.0

Response

boolTrue if the database version is supported

isSupported

Test to see if the connector is available.

isSupported() : 
static
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() : 
since

2.0.0

throws

RuntimeException

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( key = null,  column = null) : 

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

RuntimeException

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( offset) : 
since

2.0.0

throws

RuntimeException

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( class = stdClass::class) : 
since

2.0.0

throws

RuntimeException

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( key = '',  class = stdClass::class) : 

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

RuntimeException

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() : 
since

2.0.0

throws

RuntimeException

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() : 

Columns are indexed numerically so the first column in the result set would be accessible via $row[0], etc.

since

2.0.0

throws

RuntimeException

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( key = null) : 

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

RuntimeException

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( tableName) : 
since

2.0.0

throws

RuntimeException

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,  escape = true) : 
since

2.0.0

Arguments

text

array<string|int, mixed>|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( data) : 
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<string|int, mixed>|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<string|int, mixed>|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<string|int, mixed>|stringThe quote wrapped name, same type of $name.

renameTable

Renames a table in the database.

renameTable( oldTable,  newTable,  backup = null,  prefix = null) : 
since

2.0.0

throws

RuntimeException

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( sql,  prefix = '#__') : 
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( database) : 
since

2.0.0

throws

RuntimeException

Arguments

database

stringThe name of the database to select for use.

Response

bool

setQuery

Sets the SQL statement string for later execution.

setQuery( query,  offset,  limit) : 
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( toSavepoint = false) : 
since

2.0.0

throws

RuntimeException

Arguments

toSavepoint

boolIf true, commit to the last savepoint.

Response

void

transactionRollback

Method to roll back a transaction.

transactionRollback( toSavepoint = false) : 
since

2.0.0

throws

RuntimeException

Arguments

toSavepoint

boolIf true, rollback to the last savepoint.

Response

void

transactionStart

Method to initialize a transaction.

transactionStart( asSavepoint = false) : 
since

2.0.0

throws

RuntimeException

Arguments

asSavepoint

boolIf true and a transaction is already active, a savepoint will be created.

Response

void

truncateTable

Method to truncate a table.

truncateTable( table) : 
since

2.0.0

throws

RuntimeException

Arguments

table

stringThe table to truncate

Response

void

unlockTables

Unlocks tables in the database.

unlockTables() : 
since

2.0.0

throws

RuntimeException

Response

$this

updateObject

Updates a row in a table based on an object's properties.

updateObject( table,  &object, array|string key,  nulls = false) : 
since

2.0.0

throws

RuntimeException

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<string|int, mixed>|stringThe name of the primary key.

nulls

boolTrue to update null fields or false to ignore them.

Response

bool