JDatabaseMySQL

Extends \JDatabase

MySQL database driver

package

Joomla.Platform

subpackage

Database

see

http://dev.mysql.com/doc/

since

11.1

Methods

__call

Magic method to provide method alias support for quote() and quoteName().

__call(string $method, array $args) : string
inherited
since

11.1

Arguments

$method

stringThe called method.

$args

arrayThe array of arguments passed to the method.

Response

stringThe aliased method's return value or null.

__construct

Constructor.

__construct(array $options) 
inherited
since

11.1

Arguments

$options

arrayList of options used to configure the connection

__destruct

Destructor.

__destruct() 
since

11.1

addQuoted

Adds a field or array of field names to the list that are to be quoted.

addQuoted(mixed $quoted) : void
inherited deprecated
deprecated

12.1

since

11.1

Arguments

$quoted

mixedField name or array of names.

connected

Determines if the connection to the server is active.

connected() : boolean
inherited abstract
since

11.1

Response

booleanTrue if connected to the database engine.

debug

Sets the debug level on or off

debug(integer $level) : void
inherited deprecated
deprecated

12.1

since

11.1

Arguments

$level

integer0 to disable debugging and 1 to enable it.

dropTable

Drops a table from the database.

dropTable(string $table, boolean $ifExists = true) : \JDatabase
inherited abstract
since

11.4

throws

\JDatabaseException

Arguments

$table

stringThe name of the database table to drop.

$ifExists

booleanOptionally specify that the table must exist before it is dropped.

Response

\JDatabaseReturns this object to support chaining.

escape

Method to escape a string for usage in an SQL statement.

escape(string $text, boolean $extra = false) : string
inherited abstract
since

11.1

Arguments

$text

stringThe string to be escaped.

$extra

booleanOptional parameter to provide extra escaping.

Response

stringThe escaped string.

execute

Execute the SQL statement.

execute() : mixed
inherited abstract
since

12.1

throws

\JDatabaseException

Response

mixedA database cursor resource on success, boolean false on failure.

explain

Diagnostic method to return explain information for a query.

explain() : string
inherited abstract deprecated
deprecated

12.1

since

11.1

Response

stringThe explain output.

fetchArray

Method to fetch a row from the result set cursor as an array.

fetchArray(mixed $cursor = null) : mixed
inherited abstract
since

11.1

Arguments

$cursor

mixedThe optional result set cursor from which to fetch the row.

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(mixed $cursor = null) : mixed
inherited abstract
since

11.1

Arguments

$cursor

mixedThe optional result set cursor from which to fetch the row.

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(mixed $cursor = null, string $class = 'stdClass') : mixed
inherited abstract
since

11.1

Arguments

$cursor

mixedThe optional result set cursor from which to fetch the row.

$class

stringThe class name to use for the returned row object.

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(mixed $cursor = null) : void
inherited abstract
since

11.1

Arguments

$cursor

mixedThe optional result set cursor from which to fetch the row.

getAffectedRows

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

getAffectedRows() : integer
inherited abstract
since

11.1

Response

integerThe number of affected rows.

getCollation

Method to get the database collation in use by sampling a text field of a table in the database.

getCollation() : mixed
inherited abstract
since

11.1

Response

mixedThe collation in use by the database or boolean false if not supported.

getConnection

Method that provides access to the underlying database connection. Useful for when you need to call a proprietary method such as postgresql's lo_* methods.

getConnection() : resource
inherited
since

11.1

Response

resourceThe underlying database connection resource.

getConnectors

Get a list of available database connectors. The list will only be populated with connectors that both the class exists and the static test method returns true. 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.

getConnectors() : array
inherited static
since

11.1

Response

arrayAn array of available database connectors.

getCount

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

getCount() : integer
inherited
since

11.1

Response

integer

getDatabase

Gets the name of the database used by this conneciton.

getDatabase() : string
inherited
since

11.4

Response

string

getDateFormat

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

getDateFormat() : string
inherited
since

11.1

Response

stringThe format string.

getErrorMsg

Gets the error message from the database connection.

getErrorMsg(boolean $escaped = false) : string
inherited deprecated
deprecated

12.1

since

11.1

Arguments

$escaped

booleanTrue to escape the message string for use in JavaScript.

Response

stringThe error message for the most recent query.

getErrorNum

Gets the error number from the database connection.

getErrorNum() : integer
inherited deprecated
since

11.1

deprecated

12.1

Response

integerThe error number for the most recent query.

getEscaped

Method to escape a string for usage in an SQL statement.

getEscaped(string $text, boolean $extra = false) : string
inherited deprecated
since

11.1

deprecated

12.1

Arguments

$text

stringThe string to be escaped.

$extra

booleanOptional parameter to provide extra escaping.

Response

stringThe escaped string.

getExporter

Gets an exporter class object.

getExporter() : \JDatabaseExporterMySQL
since

11.1

throws

\JDatabaseException

Response

\JDatabaseExporterMySQLAn exporter object.

getImporter

Gets an importer class object.

getImporter() : \JDatabaseImporterMySQL
since

11.1

throws

\JDatabaseException

Response

\JDatabaseImporterMySQLAn importer object.

getInstance

Method to return a JDatabase instance based on the given options. There are three global options and then the rest are specific to the database driver. The 'driver' option defines which JDatabaseDriver class is used for the connection -- the default is 'mysql'. 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.

getInstance(array $options = array()) : \JDatabase
inherited static

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

11.1

Arguments

$options

arrayParameters to be passed to the database driver.

Response

\JDatabaseA database object.

getLimit

Get the row limit for the current SQL statement.

getLimit() : integer
inherited deprecated
since

2.5.17

deprecated

3.0 Required for SQLSRV support for 2.5 only

Response

integerThe affected row limit for the current SQL statement.

getLog

Get the database driver SQL statement log.

getLog() : array
inherited
since

11.1

Response

arraySQL statements executed by the database driver.

getMinimum

Get the minimum supported database version.

getMinimum() : string
inherited
since

12.1

Response

stringThe minimum version number for the database driver.

getNullDate

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

getNullDate() : string
inherited
since

11.1

Response

stringNull or zero representation of a timestamp.

getNumRows

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

getNumRows(resource $cursor = null) : integer
inherited abstract
since

11.1

Arguments

$cursor

resourceAn optional database cursor resource to extract the row count from.

Response

integerThe number of returned rows.

getOffset

Get the row offset for the current SQL statement.

getOffset() : integer
inherited deprecated
since

2.5.17

deprecated

3.0 Required for SQLSRV support for 2.5 only

Response

integerThe affected row offset to apply for the current SQL statement.

getPrefix

Get the common table prefix for the database driver.

getPrefix() : string
inherited
since

11.1

Response

stringThe common database table prefix.

getQuery

Get the current query object or a new JDatabaseQuery object.

getQuery(boolean $new = false) : \JDatabaseQuery
inherited abstract
since

11.1

throws

\JDatabaseException

Arguments

$new

booleanFalse to return the current query object, True to return a new JDatabaseQuery object.

Response

\JDatabaseQueryThe current query object or a new object extending the JDatabaseQuery class.

getTableColumns

Retrieves field information about the given tables.

getTableColumns(string $table, boolean $typeOnly = true) : array
inherited abstract
since

11.1

throws

\JDatabaseException

Arguments

$table

stringThe name of the database table.

$typeOnly

booleanTrue (default) to only return field types.

Response

arrayAn array of fields by table.

getTableCreate

Shows the table CREATE statement that creates the given tables.

getTableCreate(mixed $tables) : array
inherited abstract
since

11.1

throws

\JDatabaseException

Arguments

$tables

mixedA table name or a list of table names.

Response

arrayA list of the create SQL for the tables.

getTableFields

Retrieves field information about the given tables.

getTableFields(mixed $tables, boolean $typeOnly = true) : array
inherited deprecated
since

11.1

throws

\JDatabaseException

deprecated

12.1

Arguments

$tables

mixedA table name or a list of table names.

$typeOnly

booleanTrue to only return field types.

Response

arrayAn array of fields by table.

getTableKeys

Retrieves field information about the given tables.

getTableKeys(mixed $tables) : array
inherited abstract
since

11.1

throws

\JDatabaseException

Arguments

$tables

mixedA table name or a list of table names.

Response

arrayAn array of keys for the table(s).

getTableList

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

getTableList() : array
inherited abstract
since

11.1

throws

\JDatabaseException

Response

arrayAn array of all the tables in the database.

getTicker

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

getTicker() : integer
inherited deprecated
since

11.1

deprecated

12.1

Response

integer

getUTFSupport

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

getUTFSupport() : boolean
inherited
since

11.1

Response

booleanTrue if the database engine supports UTF-8 character encoding.

getVersion

Get the version of the database connector

getVersion() : string
inherited abstract
since

11.1

Response

stringThe database connector version.

hasUTF

Determines if the database engine supports UTF-8 character encoding.

hasUTF() : boolean
inherited abstract deprecated
since

11.1

deprecated

12.1

Response

booleanTrue if supported.

insertid

Method to get the auto-incremented value from the last INSERT statement.

insertid() : integer
inherited abstract
since

11.1

Response

integerThe 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, string $key = null) : boolean
inherited
since

11.1

throws

\JDatabaseException

Arguments

$table

stringThe name of the database table to insert into.

$object

$key

stringThe name of the primary key. If provided the object property is updated.

Response

booleanTrue on success.

isMinimumVersion

Method to check whether the installed database version is supported by the database driver

isMinimumVersion() : boolean
inherited
since

12.1

Response

booleanTrue if the database version is supported

isQuoted

Checks if field name needs to be quoted.

isQuoted(string $field) : boolean
inherited deprecated
deprecated

12.1

since

11.1

Arguments

$field

stringThe field name to be checked.

Response

boolean

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
inherited
since

11.1

throws

\JDatabaseException

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
inherited

NOTE: Chosing to key the result array by a non-unique field name can result in unwanted behavior and should be avoided.

since

11.1

throws

\JDatabaseException

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(integer $offset) : mixed
inherited
since

11.1

throws

\JDatabaseException

Arguments

$offset

integerThe row offset to use to build the result array.

Response

mixedThe return value or null if the query failed.

loadNextObject

Method to get the next row in the result set from the database query as an object.

loadNextObject(string $class = 'stdClass') : mixed
inherited
since

11.1

throws

\JDatabaseException

Arguments

$class

stringThe class name to use for the returned row object.

Response

mixedThe result of the query as an array, false if there are no more rows.

loadNextRow

Method to get the next row in the result set from the database query as an array.

loadNextRow() : mixed
inherited
since

11.1

throws

\JDatabaseException

Response

mixedThe result of the query as an array, false if there are no more rows.

loadObject

Method to get the first row of the result set from the database query as an object.

loadObject(string $class = 'stdClass') : mixed
inherited
since

11.1

throws

\JDatabaseException

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') : mixed
inherited

NOTE: Choosing to key the result array by a non-unique field name can result in unwanted behavior and should be avoided.

since

11.1

throws

\JDatabaseException

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
inherited
since

11.1

throws

\JDatabaseException

Response

mixedThe return value or null if the query failed.

loadResultArray

Method to get an array of values from the $offset field in each row of the result set from the database query.

loadResultArray(integer $offset) : mixed
inherited deprecated
since

11.1

throws

\JDatabaseException

deprecated

12.1

Arguments

$offset

integerThe row offset to use to build the result array.

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. Columns are indexed numerically so the first column in the result set would be accessible via $row[0], etc.

loadRow() : mixed
inherited
since

11.1

throws

\JDatabaseException

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
inherited

NOTE: Choosing to key the result array by a non-unique field can result in unwanted behavior and should be avoided.

since

11.1

throws

\JDatabaseException

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) : \JDatabase
inherited abstract
since

11.4

throws

\JDatabaseException

Arguments

$tableName

stringThe name of the table to unlock.

Response

\JDatabaseReturns this object to support chaining.

nameQuote

Wrap an SQL statement identifier name such as column, table or database names in quotes to prevent injection risks and reserved word conflicts.

nameQuote(string $name) : string
inherited deprecated
since

11.1

deprecated

12.1

Arguments

$name

stringThe identifier name to wrap in quotes.

Response

stringThe quote wrapped name.

query

Execute the SQL statement.

query() : mixed
inherited
since

11.1

throws

\JDatabaseException

Response

mixedA database cursor resource on success, boolean false on failure.

queryBatch

Execute a query batch.

queryBatch(boolean $abortOnError = true, boolean $transactionSafe = false) : mixed
inherited abstract deprecated
deprecated

12.1

since

11.1

Arguments

$abortOnError

booleanAbort on error.

$transactionSafe

booleanTransaction safe queries.

Response

mixedA database resource if successful, false if not.

quote

Method to quote and optionally escape a string to database requirements for insertion into the database.

quote(string $text, boolean $escape = true) : string
inherited
since

11.1

Arguments

$text

stringThe string to quote.

$escape

booleanTrue (default) to escape the string, false to leave it unchanged.

Response

stringThe 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(mixed $name, mixed $as = null) : mixed
inherited
since

11.1

Arguments

$name

mixedThe identifier name to wrap in quotes, or an array of identifier names to wrap in quotes. Each type supports dot-notation name.

$as

mixedThe 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

mixedThe quote wrapped name, same type of $name.

quoteNameStr

Quote strings coming from quoteName call.

quoteNameStr(array $strArr) : string
inherited
since

11.3

Arguments

$strArr

arrayArray of strings coming from quoteName dot-explosion.

Response

stringDot-imploded string of quoted parts.

renameTable

Renames a table in the database.

renameTable(string $oldTable, string $newTable, string $backup = null, string $prefix = null) : \JDatabase
inherited abstract
since

11.4

throws

\JDatabaseException

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

\JDatabaseReturns this object to support chaining.

replacePrefix

This function replaces a string identifier $prefix with the string held is the tablePrefix class variable.

replacePrefix(string $sql, string $prefix = '#__') : string
inherited
since

11.1

Arguments

$sql

stringThe SQL statement to prepare.

$prefix

stringThe common table prefix.

Response

stringThe processed SQL statement.

select

Select a database for use.

select(string $database) : boolean
inherited abstract
since

11.1

throws

\JDatabaseException

Arguments

$database

stringThe name of the database to select for use.

Response

booleanTrue if the database was successfully selected.

setDebug

Sets the database debugging state for the driver.

setDebug(boolean $level) : boolean
inherited
since

11.1

Arguments

$level

booleanTrue to enable debugging.

Response

booleanThe old debugging level.

setQuery

Sets the SQL statement string for later execution.

setQuery(mixed $query, integer $offset, integer $limit) : \JDatabase
inherited
since

11.1

Arguments

$query

mixedThe SQL statement to set either as a JDatabaseQuery object or a string.

$offset

integerThe affected row offset to set.

$limit

integerThe maximum affected rows to set.

Response

\JDatabaseThis object to support method chaining.

setUTF

Set the connection to use UTF-8 character encoding.

setUTF() : boolean
inherited abstract
since

11.1

Response

booleanTrue on success.

splitSql

Splits a string of multiple queries into an array of individual queries.

splitSql(string $sql) : array
inherited static
since

11.1

Arguments

$sql

stringInput SQL string with which to split into individual queries.

Response

arrayThe queries from the input string separated into an array.

stderr

Return the most recent error message for the database connector.

stderr(boolean $showSQL = false) : string
inherited deprecated
deprecated

12.1

since

11.1

Arguments

$showSQL

booleanTrue to display the SQL statement sent to the database as well as the error.

Response

stringThe error message for the most recent query.

test

Test to see if the MySQL connector is available.

test() : boolean
static
since

11.1

Response

booleanTrue on success, false otherwise.

transactionCommit

Method to commit a transaction.

transactionCommit() : void
inherited abstract
since

11.1

throws

\JDatabaseException

transactionRollback

Method to roll back a transaction.

transactionRollback() : void
inherited abstract
since

11.1

throws

\JDatabaseException

transactionStart

Method to initialize a transaction.

transactionStart() : void
inherited abstract
since

11.1

throws

\JDatabaseException

truncateTable

Method to truncate a table.

truncateTable(string $table) : void
inherited
since

11.3

throws

\JDatabaseException

Arguments

$table

stringThe table to truncate

unlockTables

Unlocks tables in the database.

unlockTables() : \JDatabase
inherited abstract
since

11.4

throws

\JDatabaseException

Response

\JDatabaseReturns this object to support chaining.

updateObject

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

updateObject(string $table,  &$object, string $key, boolean $nulls = false) : boolean
inherited
since

11.1

throws

\JDatabaseException

Arguments

$table

stringThe name of the database table to update.

$object

$key

stringThe name of the primary key.

$nulls

booleanTrue to update null fields or false to ignore them.

Response

booleanTrue on success.

Properties

name

The name of the database driver.

inherited
since

11.1

Type(s)

string

nameQuote

The character(s) used to quote SQL statement names such as table names or field names, etc. The child classes should define this as necessary. 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.

inherited
since

11.1

Type(s)

string

nullDate

The null or zero representation of a timestamp for the database driver. This should be defined in child classes to hold the appropriate value for the engine.

inherited
since

11.1

Type(s)

string

dbMinimum

The minimum supported database version.

inherited
since

12.1

Type(s)

string

_database

The name of the database.

inherited
since

11.4

Type(s)

string

connection

The database connection resource.

inherited
since

11.1

Type(s)

resource

count

The number of SQL statements executed by the database driver.

inherited
since

11.1

Type(s)

integer

cursor

The database connection cursor from the last query.

inherited
since

11.1

Type(s)

resource

debug

The database driver debugging state.

inherited
since

11.1

Type(s)

boolean

limit

The affected row limit for the current SQL statement.

inherited
since

11.1

Type(s)

integer

log

The log of executed SQL statements by the database driver.

inherited
since

11.1

Type(s)

array

offset

The affected row offset to apply for the current SQL statement.

inherited
since

11.1

Type(s)

integer

sql

The current SQL statement to execute.

inherited
since

11.1

Type(s)

mixed

tablePrefix

The common database table prefix.

inherited
since

11.1

Type(s)

string

utf

True if the database engine supports UTF-8 character encoding.

inherited
since

11.1

Type(s)

boolean

errorNum

The database error number

inherited deprecated
since

11.1

deprecated

12.1

Type(s)

integer

errorMsg

The database error message

inherited deprecated
since

11.1

deprecated

12.1

Type(s)

string

hasQuoted

If true then there are fields to be quoted for the query.

inherited deprecated
since

11.1

deprecated

12.1

Type(s)

boolean

quoted

The fields that are to be quoted.

inherited deprecated
since

11.1

deprecated

12.1

Type(s)

array

instances

JDatabase instances container.

inherited static
since

11.1

Type(s)

array