DatabaseDriver
Implements DatabaseInterface, DispatcherAwareInterfaceJoomla Framework Database Driver Class
| since |
1.0 |
|---|---|
| package |
Joomla Framework |
Methods
__construct
Constructor.
__construct(mixed||string|int options) :
| since |
1.0 |
|---|
Arguments
- options
array<string|int, mixed>List of options used to configure the connection
Response
mixed
__destruct
Destructor.
__destruct() :
| since |
2.0.0 |
|---|
Response
mixed
__get
Magic method to access properties of the database driver.
__get( name) :
| since |
1.4.0 |
|---|---|
| deprecated |
3.0 This is a B/C proxy since $this->name was previously public |
Arguments
- name
stringThe name of the property.
Response
mixedA value if the property name is valid, null otherwise.
alterDbCharacterSet
Alter database's character set.
alterDbCharacterSet( dbName) : bool|resource
| since |
2.0.0 |
|---|---|
| throws |
|
Arguments
- dbName
stringThe database name that will be altered
Response
bool|resource
createDatabase
Create a new database using information from $options object.
createDatabase(\stdClass options, 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
createQuery
Create a new DatabaseQuery object.
createQuery() : \Joomla\Database\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
dispatchEvent
Dispatch an event.
dispatchEvent(\Joomla\Event\EventInterface event) :
dropTable
Drops a table from the database.
dropTable( table, ifExists = true) :
| 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
execute
Execute the SQL statement.
execute() :
| since |
2.0.0 |
|---|---|
| throws |
|
Response
bool
extractHostPortSocket
Extract pure host name (or IP address) and port or socket from host name option.
extractHostPortSocket( host, int|null port, string|null socket, defaultPort, ipv6SquareBrackets = true) : mixed||string|int
| since |
3.3.0 |
|---|
Arguments
- host
stringHost given in options used to configure the connection.- port
int|nullPort given in options used to configure the connection, null if none.- socket
string|nullSocket given in options used to configure the connection, null if none.- defaultPort
intThe default port number to be used if no port is given.- ipv6SquareBrackets
boolTrue if database connector uses ipv6 address with square brackets, false if not.
Response
array<string|int, mixed>Array with host, port and socket.
fetchArray
Method to fetch a row from the result set cursor as an array.
fetchArray() :
| since |
1.0 |
|---|
Response
mixedEither the next row from the result set or false if there are no more rows.
fetchAssoc
Method to fetch a row from the result set cursor as an associative array.
fetchAssoc() :
| since |
1.0 |
|---|
Response
mixedEither the next row from the result set or false if there are no more rows.
fetchObject
Method to fetch a row from the result set cursor as an object.
fetchObject() :
Note, the fetch mode should be configured before calling this method using StatementInterface::setFetchMode().
| since |
1.0 |
|---|
Response
mixedEither the next row from the result set or false if there are no more rows.
freeResult
Method to free up the memory used for the result set.
freeResult() :
| since |
1.0 |
|---|
Response
void
getAffectedRows
Get the number of affected rows for the previous executed SQL statement.
getAffectedRows() :
| since |
2.0.0 |
|---|
Response
intThe number of affected rows in the previous operation
getAlterDbCharacterSet
Return the query string to alter the database character set.
getAlterDbCharacterSet( dbName) :
| since |
1.6.0 |
|---|
Arguments
- dbName
stringThe database name
Response
stringThe query that alter the database query string
getConnection
Method that provides access to the underlying database connection.
getConnection() :
| since |
1.0 |
|---|
Response
resourceThe underlying database connection resource.
getConnectors
Get a list of available database connectors.
getConnectors() : mixed||string|int
The list will only be populated with connectors that the class exists for and the environment supports its use. This gives us the ability to have a multitude of connector classes that are self-aware as to whether or not they are able to be used on a given system.
| since |
1.0 |
|---|
Response
array<string|int, mixed>An array of available database connectors.
getCount
Get the total number of SQL statements executed by the database driver.
getCount() :
| since |
1.0 |
|---|
Response
int
getCreateDatabaseQuery
Return the query string to create new Database.
getCreateDatabaseQuery(\stdClass options, utf) :
| since |
2.0.0 |
|---|
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
stringThe query that creates database
getDatabase
Gets the name of the database used by this connection.
getDatabase() :
| since |
1.0 |
|---|
Response
string
getDateFormat
Returns a PHP date() function compliant date format for the database driver.
getDateFormat() :
| since |
1.0 |
|---|
Response
string
getDispatcher
Get the event dispatcher.
getDispatcher() : \Joomla\Event\DispatcherInterface
| since |
1.2.0 |
|---|---|
| throws |
|
Response
getExporter
Gets an exporter class object.
getExporter() : \Joomla\Database\DatabaseExporter
getImporter
Gets an importer class object.
getImporter() : \Joomla\Database\DatabaseImporter
getInstance
Method to return a DatabaseDriver instance based on the given options.
getInstance(mixed||string|int options = []) : \Joomla\Database\DatabaseDriver
There are three global options and then the rest are specific to the database driver.
- The 'driver' option defines which DatabaseDriver class is used for the connection -- the default is 'mysqli'.
- The 'database' option determines which database is to be used for the connection.
- The 'select' option determines whether the connector should automatically select the chosen database.
Instances are unique to the given options and new objects are only created when a unique options array is passed into the method. This ensures that we don't end up with unnecessary database connection resources.
| since |
1.0 |
|---|---|
| throws |
|
| deprecated |
3.0 Use DatabaseFactory::getDriver() instead |
Arguments
- options
array<string|int, mixed>Parameters to be passed to the database driver.
Response
getIterator
Get a new iterator on the current query.
getIterator( column = null, class = stdClass::class) : \Joomla\Database\DatabaseIterator
| since |
1.0 |
|---|
Arguments
- column
stringAn option column to use as the iterator key.- class
stringThe class of object that is returned.
Response
getMinimum
Get the minimum supported database version.
getMinimum() :
| since |
1.0 |
|---|
Response
string
getMonitor
Get the query monitor.
getMonitor() : \Joomla\Database\QueryMonitorInterface|null
getName
Get the name of the database driver.
getName() :
If $this->name is not set it will try guessing the driver name from the class name.
| since |
1.4.0 |
|---|
Response
string
getNullDate
Get the null or zero representation of a timestamp for the database driver.
getNullDate() :
| since |
1.0 |
|---|
Response
string
getNumRows
Get the number of returned rows for the previous executed SQL statement.
getNumRows() :
| since |
2.0.0 |
|---|
Response
intThe number of returned rows.
getPrefix
Get the common table prefix for the database driver.
getPrefix() :
| since |
1.0 |
|---|
Response
stringThe common database table prefix.
getQuery
Get the current query object or a new DatabaseQuery object.
getQuery( new = false) : \Joomla\Database\DatabaseQuery
| since |
1.0 |
|---|
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 4.0, use createQuery() instead.
Response
getServerType
Get the server family type.
getServerType() :
If $this->serverType is not set it will attempt guessing the server family type from the driver name. If this is not possible the driver name will be returned instead.
| since |
1.4.0 |
|---|
Response
string
getTableCreate
Shows the table CREATE statement that creates the given tables.
getTableCreate( tables) : mixed||string|int
| since |
1.0 |
|---|---|
| throws |
|
Arguments
- tables
mixedA table name or a list of table names.
Response
array<string|int, mixed>A list of the create SQL for the tables.
hasUtfSupport
Determine whether or not the database engine supports UTF-8 character encoding.
hasUtfSupport() :
| since |
1.0 |
|---|
Response
boolTrue if the database engine supports UTF-8 character encoding.
insertObject
Inserts a row into a table based on an object's properties.
insertObject( table, &object, key = null) :
| since |
1.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
isMinimumVersion
Method to check whether the installed database version is supported by the database driver
isMinimumVersion() :
| since |
1.0 |
|---|
Response
boolTrue if the database version is supported
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 |
1.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( 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 |
1.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( offset) :
| since |
1.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( class = stdClass::class) :
| since |
1.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( 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 |
1.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() :
| since |
1.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() :
Columns are indexed numerically so the first column in the result set would be accessible via $row[0], etc.
| since |
1.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( key = null) : mixed||string|int
NOTE: Choosing to key the result array by a non-unique field can result in unwanted behavior and should be avoided.
| since |
1.0 |
|---|---|
| throws |
|
Arguments
- key
stringThe name of a field on which to key the result array.
Response
array<string|int, mixed>An array of results.
prepareStatement
Prepares a SQL statement for execution
prepareStatement( query) : \Joomla\Database\StatementInterface
| since |
2.0.0 |
|---|---|
| throws |
Arguments
- query
stringThe SQL query to be prepared.
Response
q
Alias for quote method
q(array|string text, escape = true) :
| since |
1.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
stringThe quoted input string.
qn
Alias for quoteName method
qn(array|string name, array|string as = null) : array|string
| since |
1.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.
quote
Quotes and optionally escapes a string to database requirements for use in database queries.
quote(array|string text, escape = true) : array|string
| since |
1.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
array<string|int, mixed>|stringThe quoted input 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 |
1.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.
quoteNameStr
Quote strings coming from quoteName call.
quoteNameStr(mixed||string|int strArr) :
| since |
1.0 |
|---|---|
| deprecated |
2.0 Use quoteNameString instead |
Arguments
- strArr
array<string|int, mixed>Array of strings coming from quoteName dot-explosion.
Response
stringDot-imploded string of quoted parts.
quoteNameString
Quote string coming from quoteName call.
quoteNameString( name, asSinglePart = false) :
| since |
1.7.0 |
|---|
Arguments
- name
stringIdentifier name to be quoted.- asSinglePart
boolTreat the name as a single part of the identifier.
Response
stringQuoted identifier string.
replacePrefix
This function replaces a string identifier with the configured table prefix.
replacePrefix( sql, prefix = '#__') :
| since |
1.0 |
|---|
Arguments
- sql
stringThe SQL statement to prepare.- prefix
stringThe table prefix.
Response
stringThe processed SQL statement.
setDispatcher
Set the dispatcher to use.
setDispatcher(\Joomla\Event\DispatcherInterface dispatcher) :
setMonitor
Set a query monitor.
setMonitor(\Joomla\Database\QueryMonitorInterface|null monitor = null) :
setQuery
Sets the SQL statement string for later execution.
setQuery(string|\Joomla\Database\QueryInterface query, offset, limit) :
| since |
1.0 |
|---|---|
| throws |
|
Arguments
- query
string|QueryInterfaceThe 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
setUtf
Set the connection to use UTF-8 character encoding.
setUtf() :
| since |
1.0 |
|---|
Response
boolTrue on success.
splitSql
Splits a string of multiple queries into an array of individual queries.
splitSql( sql) : mixed||string|int
| since |
1.0 |
|---|
Arguments
- sql
stringInput SQL string with which to split into individual queries.
Response
array<string|int, mixed>
truncateTable
Method to truncate a table.
truncateTable( table) :
| since |
1.0 |
|---|---|
| throws |
|
Arguments
- table
stringThe table to truncate
Response
void
updateObject
Updates a row in a table based on an object's properties.
updateObject( table, &object, array|string key, nulls = false) :
| since |
1.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<string|int, mixed>|stringThe name of the primary key.- nulls
boolTrue to update null fields or false to ignore them.
Response
boolTrue on success.
Properties
database
The name of the database.
| since |
1.0 |
|---|
Type(s)
string
name
The name of the database driver.
| since |
1.0 |
|---|
Type(s)
string
serverType
The type of the database server family supported by this driver.
| since |
1.4.0 |
|---|
Type(s)
string
connection
The database connection resource.
| since |
1.0 |
|---|
Type(s)
resource
connectors
Holds the list of available db connectors.
| since |
1.0 |
|---|
Type(s)
array<string|int, mixed>
count
The number of SQL statements executed by the database driver.
| since |
1.0 |
|---|
Type(s)
int
cursor
The database connection cursor from the last query.
| since |
1.0 |
|---|
Type(s)
resource
executed
Contains the current query execution status
| since |
2.0.0 |
|---|
Type(s)
bool
limit
The affected row limit for the current SQL statement.
| since |
1.0 |
|---|
Type(s)
int
nameQuote
The character(s) used to quote SQL statement names such as table names or field names, etc.
If a single character string the same character is used for both sides of the quoted name, else the first character will be used for the opening quote and the second for the closing quote.
| since |
1.0 |
|---|
Type(s)
string
nullDate
The null or zero representation of a timestamp for the database driver.
| since |
1.0 |
|---|
Type(s)
string
offset
The affected row offset to apply for the current SQL statement.
| since |
1.0 |
|---|
Type(s)
int
options
Passed in upon instantiation and saved.
| since |
1.0 |
|---|
Type(s)
array<string|int, mixed>
sql
The current SQL statement to execute.
| since |
1.0 |
|---|
Type(s)
mixed
tablePrefix
The common database table prefix.
| since |
1.0 |
|---|
Type(s)
string
utf
True if the database engine supports UTF-8 character encoding.
| since |
1.0 |
|---|
Type(s)
bool
errorNum
The database error number.
| since |
1.0 |
|---|
Type(s)
int
errorMsg
The database error message.
| since |
1.0 |
|---|
Type(s)
string
instances
DatabaseDriver instances container.
| since |
1.0 |
|---|---|
| deprecated |
3.0 Singleton storage will no longer be supported. |
Type(s)
array<string|int, DatabaseDriver>
dbMinimum
The minimum supported database version.
| since |
1.0 |
|---|
Type(s)
string
transactionDepth
The depth of the current transaction.
| since |
1.0 |
|---|
Type(s)
int