Actions

API17

Difference between revisions of "JDatabase"

From Joomla! Documentation

(Layout updates)
m (User contributed notes: bad link repair)
(One intermediate revision by one user not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 +
=={{JVer|11.1}} JDatabase==
 +
===Description===
 +
{{Description:JDatabase}}
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[Description:JDatabase|Edit Descripton]]<nowiki>]</nowiki>
 
<nowiki>[</nowiki>[[Description:JDatabase|Edit Descripton]]<nowiki>]</nowiki>
 
</span>
 
</span>
{{Description:JDatabase}}
 
===Defined in===
 
libraries/joomla/database/database.php
 
* see source code in [[jplatform:database/database.php|BitBucket]]
 
===Subpackage===
 
[[Subpackage Database/11.1|Database]]
 
===Extends===
 
[[JObject/11.1|JObject]]
 
===Extended by===
 
* [[JDatabaseMySQL/11.1|JDatabaseMySQL]]
 
* [[JDatabaseMySQLi/11.1|JDatabaseMySQLi]]
 
 
===Methods===
 
===Methods===
 
{| class="wikitable sortable"
 
{| class="wikitable sortable"
 
|-
 
|-
 +
!Visibility
 
!Method name
 
!Method name
 
!Description
 
!Description
 
|-
 
|-
|[[JDatabase::__construct/11.1|__construct]]
+
|public
|Database object constructor.
+
|[[JDatabase::__call/11.1|__call]]
|-
+
|Magic method to provide method alias support for  and .  
|[[JDatabase::__destruct/11.1|__destruct]]
+
|Database object destructor.  
+
 
|-
 
|-
 +
|public
 
|[[JDatabase::addQuoted/11.1|addQuoted]]
 
|[[JDatabase::addQuoted/11.1|addQuoted]]
 
|Adds a field or array of field names to the list that are to be quoted.  
 
|Adds a field or array of field names to the list that are to be quoted.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::connected/11.1|connected]]
 
|[[JDatabase::connected/11.1|connected]]
 
|Determines if the connection to the server is active.  
 
|Determines if the connection to the server is active.  
 
|-
 
|-
 +
|public
 +
|[[JDatabase::dateToString/11.1|dateToString]]
 +
|Method to get a  object represented as a datetime string in a format recognized by the database server.
 +
|-
 +
|public
 
|[[JDatabase::debug/11.1|debug]]
 
|[[JDatabase::debug/11.1|debug]]
 
|Sets the debug level on or off.  
 
|Sets the debug level on or off.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::explain/11.1|explain]]
 
|[[JDatabase::explain/11.1|explain]]
|Diagnostic function.  
+
|Diagnostic method to return explain information for a query.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::getAffectedRows/11.1|getAffectedRows]]
 
|[[JDatabase::getAffectedRows/11.1|getAffectedRows]]
|Get the affected rows by the most recent query.  
+
|Get the number of affected rows for the previous executed SQL statement.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::getCollation/11.1|getCollation]]
 
|[[JDatabase::getCollation/11.1|getCollation]]
|Get the database collation.  
+
|Method to get the database collation in use by sampling a text field of a table in the database.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::getConnection/11.1|getConnection]]
 
|[[JDatabase::getConnection/11.1|getConnection]]
|Get the connection.  
+
|Method that provides access to the underlying database connection.  
 
|-
 
|-
|[[JDatabase::getConnectors/11.1|getConnectors]]
+
|public
|Get the database connectors.  
+
|[[JDatabase::getCount/11.1|getCount]]
 +
|Get the total number of SQL statements executed by the database driver.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::getErrorMsg/11.1|getErrorMsg]]
 
|[[JDatabase::getErrorMsg/11.1|getErrorMsg]]
|Get the error message.  
+
|Gets the error message from the database connection.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::getErrorNum/11.1|getErrorNum]]
 
|[[JDatabase::getErrorNum/11.1|getErrorNum]]
|Get the error number.  
+
|Gets the error number from the database connection.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::getEscaped/11.1|getEscaped]]
 
|[[JDatabase::getEscaped/11.1|getEscaped]]
|Get a database escaped string.  
+
|Method to escape a string for usage in an SQL statement.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::getLog/11.1|getLog]]
 
|[[JDatabase::getLog/11.1|getLog]]
|Get a database error log.  
+
|Get the database driver SQL statement log.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::getNullDate/11.1|getNullDate]]
 
|[[JDatabase::getNullDate/11.1|getNullDate]]
|Get the database null date.  
+
|Get the null or zero representation of a timestamp for the database driver.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::getNumRows/11.1|getNumRows]]
 
|[[JDatabase::getNumRows/11.1|getNumRows]]
|Get the number of rows returned by the most recent query.  
+
|Get the number of returned rows for the previous executed SQL statement.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::getPrefix/11.1|getPrefix]]
 
|[[JDatabase::getPrefix/11.1|getPrefix]]
|Get the database table prefix.  
+
|Get the common table prefix for the database driver.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::getQuery/11.1|getQuery]]
 
|[[JDatabase::getQuery/11.1|getQuery]]
 
|Get the current or query, or new  object.  
 
|Get the current or query, or new  object.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::getTableCreate/11.1|getTableCreate]]
 
|[[JDatabase::getTableCreate/11.1|getTableCreate]]
|Shows the CREATE TABLE statement that creates the given tables.  
+
|Shows the table CREATE statement that creates the given tables.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::getTableFields/11.1|getTableFields]]
 
|[[JDatabase::getTableFields/11.1|getTableFields]]
|Retrieves information about the given tables.  
+
|Retrieves field information about the given tables.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::getTableList/11.1|getTableList]]
 
|[[JDatabase::getTableList/11.1|getTableList]]
|List tables in a database.  
+
|Method to get an array of all tables in the database.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::getTicker/11.1|getTicker]]
 
|[[JDatabase::getTicker/11.1|getTicker]]
|Get the total number of queries made.  
+
|Get the total number of SQL statements executed by the database driver.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::getUTFSupport/11.1|getUTFSupport]]
 
|[[JDatabase::getUTFSupport/11.1|getUTFSupport]]
|Get the database UTF-8 support.  
+
|Determine whether or not the database engine supports UTF-8 character encoding.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::getVersion/11.1|getVersion]]
 
|[[JDatabase::getVersion/11.1|getVersion]]
 
|Get the version of the database connector.  
 
|Get the version of the database connector.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::hasUTF/11.1|hasUTF]]
 
|[[JDatabase::hasUTF/11.1|hasUTF]]
|Determines UTF support.  
+
|Determines if the database engine supports UTF-8 character encoding.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::insertid/11.1|insertid]]
 
|[[JDatabase::insertid/11.1|insertid]]
|Get the ID generated from the previous INSERT operation.  
+
|Method to get the auto-incremented value from the last INSERT statement.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::insertObject/11.1|insertObject]]
 
|[[JDatabase::insertObject/11.1|insertObject]]
|Inserts a row into a table based on an objects properties.  
+
|Inserts a row into a table based on an object's properties.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::isQuoted/11.1|isQuoted]]
 
|[[JDatabase::isQuoted/11.1|isQuoted]]
 
|Checks if field name needs to be quoted.  
 
|Checks if field name needs to be quoted.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::loadAssoc/11.1|loadAssoc]]
 
|[[JDatabase::loadAssoc/11.1|loadAssoc]]
|Fetch a result row as an associative array.  
+
|Method to get the first row of the result set from the database query as an associative array of ['field_name' => 'row_value'].  
 
|-
 
|-
 +
|public
 
|[[JDatabase::loadAssocList/11.1|loadAssocList]]
 
|[[JDatabase::loadAssocList/11.1|loadAssocList]]
|Load a associactive list of database rows.  
+
|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'].  
 
|-
 
|-
 +
|public
 
|[[JDatabase::loadNextObject/11.1|loadNextObject]]
 
|[[JDatabase::loadNextObject/11.1|loadNextObject]]
|Load the next row returned by the query.  
+
|Method to get the next row in the result set from the database query as an object.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::loadNextRow/11.1|loadNextRow]]
 
|[[JDatabase::loadNextRow/11.1|loadNextRow]]
|Load the next row returned by the query.  
+
|Method to get the next row in the result set from the database query as an array.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::loadObject/11.1|loadObject]]
 
|[[JDatabase::loadObject/11.1|loadObject]]
|This global function loads the first row of a query into an object.  
+
|Method to get the first row of the result set from the database query as an object.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::loadObjectList/11.1|loadObjectList]]
 
|[[JDatabase::loadObjectList/11.1|loadObjectList]]
|Load a list of database objects.  
+
|Method to get an array of the result set rows from the database query where each row is an object.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::loadResult/11.1|loadResult]]
 
|[[JDatabase::loadResult/11.1|loadResult]]
|This method loads the first field of the first row returned by the query.  
+
|Method to get the first field of the first row of the result set from the database query.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::loadResultArray/11.1|loadResultArray]]
 
|[[JDatabase::loadResultArray/11.1|loadResultArray]]
|Load an array of single field results into an array.  
+
|Method to get an array of values from the  field in each row of the result set from the database query.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::loadRow/11.1|loadRow]]
 
|[[JDatabase::loadRow/11.1|loadRow]]
|Load the first row returned by the query.  
+
|Method to get the first row of the result set from the database query as an array.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::loadRowList/11.1|loadRowList]]
 
|[[JDatabase::loadRowList/11.1|loadRowList]]
|Load a list of database rows (numeric column indexing).  
+
|Method to get an array of the result set rows from the database query where each row is an array.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::nameQuote/11.1|nameQuote]]
 
|[[JDatabase::nameQuote/11.1|nameQuote]]
|Quote an identifier name (field, table, etc).  
+
|Wrap an SQL statement identifier name such as field, table or database names in quotes to prevent injection risks and reserved word conflicts.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::query/11.1|query]]
 
|[[JDatabase::query/11.1|query]]
|Execute the query.  
+
|Execute the SQL statement.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::queryBatch/11.1|queryBatch]]
 
|[[JDatabase::queryBatch/11.1|queryBatch]]
|Execute a batch query.  
+
|Execute a query batch.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::quote/11.1|quote]]
 
|[[JDatabase::quote/11.1|quote]]
|Get a quoted database escaped string.  
+
|Method to quote and optionally escape a string to database requirements for insertion into the database.  
 
|-
 
|-
|[[JDatabase::replacePrefix/11.1|replacePrefix]]
+
|public
|This function replaces a string identifier  with the string held is the  class variable.  
+
|[[JDatabase::select/11.1|select]]
 +
|Select a database for use.  
 
|-
 
|-
 +
|public
 +
|[[JDatabase::setDebug/11.1|setDebug]]
 +
|Sets the database debugging state for the driver.
 +
|-
 +
|public
 
|[[JDatabase::setQuery/11.1|setQuery]]
 
|[[JDatabase::setQuery/11.1|setQuery]]
|Sets the SQL query string for later execution.  
+
|Sets the SQL statement string for later execution.  
 
|-
 
|-
 +
|public
 
|[[JDatabase::setUTF/11.1|setUTF]]
 
|[[JDatabase::setUTF/11.1|setUTF]]
|Custom settings for UTF support.
+
|Set the connection to use UTF-8 character encoding.  
|-
+
|[[JDatabase::splitSql/11.1|splitSql]]
+
|Splits a string of queries into an array of individual queries.  
+
 
|-
 
|-
 +
|public
 
|[[JDatabase::stderr/11.1|stderr]]
 
|[[JDatabase::stderr/11.1|stderr]]
|Print out an error statement.  
+
|Return the most recent error message for the database connector.  
 
|-
 
|-
|[[JDatabase::test/11.1|test]]
+
|public
|Test to see if the MySQLi connector is available.  
+
|[[JDatabase::transactionCommit/11.1|transactionCommit]]
 +
|Method to commit a transaction.  
 
|-
 
|-
 +
|public
 +
|[[JDatabase::transactionRollback/11.1|transactionRollback]]
 +
|Method to roll back a transaction.
 +
|-
 +
|public
 +
|[[JDatabase::transactionStart/11.1|transactionStart]]
 +
|Method to initialize a transaction.
 +
|-
 +
|public
 
|[[JDatabase::updateObject/11.1|updateObject]]
 
|[[JDatabase::updateObject/11.1|updateObject]]
|Update an object in the database.  
+
|Updates a row in a table based on an object's properties.  
 
|-
 
|-
 +
|public static
 +
|[[JDatabase::getConnectors/11.1|getConnectors]]
 +
|Get a list of available database connectors.
 +
|-
 +
|public static
 
|[[JDatabase::getInstance/11.1|getInstance]]
 
|[[JDatabase::getInstance/11.1|getInstance]]
|Returns the global Database object, only creating it if it doesn't already exist.  
+
|Method to return a  instance based on the given options.
 +
|-
 +
|public static
 +
|[[JDatabase::splitSql/11.1|splitSql]]
 +
|Splits a string of multiple queries into an array of individual queries.
 +
|-
 +
|public static
 +
|[[JDatabase::test/11.1|test]]
 +
|Test to see if the connector is available.
 +
|-
 +
|protected
 +
|[[JDatabase::__construct/11.1|__construct]]
 +
|Constructor.
 +
|-
 +
|protected
 +
|[[JDatabase::fetchArray/11.1|fetchArray]]
 +
|Method to fetch a row from the result set cursor as an array.
 +
|-
 +
|protected
 +
|[[JDatabase::fetchAssoc/11.1|fetchAssoc]]
 +
|Method to fetch a row from the result set cursor as an associative array.
 +
|-
 +
|protected
 +
|[[JDatabase::fetchObject/11.1|fetchObject]]
 +
|Method to fetch a row from the result set cursor as an object.
 +
|-
 +
|protected
 +
|[[JDatabase::freeResult/11.1|freeResult]]
 +
|Method to free up the memory used for the result set.
 +
|-
 +
|protected
 +
|[[JDatabase::replacePrefix/11.1|replacePrefix]]
 +
|This function replaces a string identifier  with the string held is the  class variable.  
 
|-
 
|-
 
|}
 
|}
 +
* '''Defined in''' libraries/joomla/database/database.php
 +
* '''Extended by'''
 +
** [[JDatabaseMySQL/11.1|JDatabaseMySQL]]
 +
** [[JDatabaseMySQLi/11.1|JDatabaseMySQLi]]
 +
** [[JDatabaseSQLAzure/11.1|JDatabaseSQLAzure]]
 +
** [[JDatabaseSQLSrv/11.1|JDatabaseSQLSrv]]
 
===Importing===
 
===Importing===
 
<source lang="php">jimport( 'joomla.database.database' );</source>
 
<source lang="php">jimport( 'joomla.database.database' );</source>
 
===See also===
 
===See also===
* JDatabase source code in [[jplatform:database/database.php|BitBucket]]
+
* {{JVer|11.1}} '''JDatabase source code''' on [[jplatform:database/database.php|BitBucket]]
* [[JDatabase|Other versions of this class]]
+
* {{JVer|11.1}} Subpackage [[Subpackage Database/11.1|Database]]
 +
* [[JDatabase|Other versions of JDatabase]]
 
{{SeeAlso:JDatabase}}
 
{{SeeAlso:JDatabase}}
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[SeeAlso:JDatabase|Edit See Also]]<nowiki>]</nowiki>
 
<nowiki>[</nowiki>[[SeeAlso:JDatabase|Edit See Also]]<nowiki>]</nowiki>
 
</span>
 
</span>
===Examples===
+
===User contributed notes===
 
<CodeExamplesForm />
 
<CodeExamplesForm />
 
<dpl>
 
<dpl>
Line 188: Line 282:
 
category=ClassExample
 
category=ClassExample
 
include=*
 
include=*
 +
namespace=CodeExample
 
format= ,,,
 
format= ,,,
 
</dpl>
 
</dpl>
<noinclude>[[Category:Platform]][[Category:Platform 11.1]][[Category:JDatabase]]</noinclude>
+
<noinclude>[[Category:Platform JClasses]][[Category:Platform 11.1]][[Category:JDatabase]]</noinclude>

Revision as of 13:33, 29 August 2012

Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Joomla 11.1 JDatabase

Description

JDatabase is an abstract class which is extended by specific database drivers. It provides database connections for Joomla. [Edit Descripton]

Methods

Visibility Method name Description
public __call Magic method to provide method alias support for and .
public addQuoted Adds a field or array of field names to the list that are to be quoted.
public connected Determines if the connection to the server is active.
public dateToString Method to get a object represented as a datetime string in a format recognized by the database server.
public debug Sets the debug level on or off.
public explain Diagnostic method to return explain information for a query.
public getAffectedRows Get the number of affected rows for the previous executed SQL statement.
public getCollation Method to get the database collation in use by sampling a text field of a table in the database.
public getConnection Method that provides access to the underlying database connection.
public getCount Get the total number of SQL statements executed by the database driver.
public getErrorMsg Gets the error message from the database connection.
public getErrorNum Gets the error number from the database connection.
public getEscaped Method to escape a string for usage in an SQL statement.
public getLog Get the database driver SQL statement log.
public getNullDate Get the null or zero representation of a timestamp for the database driver.
public getNumRows Get the number of returned rows for the previous executed SQL statement.
public getPrefix Get the common table prefix for the database driver.
public getQuery Get the current or query, or new object.
public getTableCreate Shows the table CREATE statement that creates the given tables.
public getTableFields Retrieves field information about the given tables.
public getTableList Method to get an array of all tables in the database.
public getTicker Get the total number of SQL statements executed by the database driver.
public getUTFSupport Determine whether or not the database engine supports UTF-8 character encoding.
public getVersion Get the version of the database connector.
public hasUTF Determines if the database engine supports UTF-8 character encoding.
public insertid Method to get the auto-incremented value from the last INSERT statement.
public insertObject Inserts a row into a table based on an object's properties.
public isQuoted Checks if field name needs to be quoted.
public loadAssoc Method to get the first row of the result set from the database query as an associative array of ['field_name' => 'row_value'].
public 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'].
public loadNextObject Method to get the next row in the result set from the database query as an object.
public loadNextRow Method to get the next row in the result set from the database query as an array.
public loadObject Method to get the first row of the result set from the database query as an object.
public loadObjectList Method to get an array of the result set rows from the database query where each row is an object.
public loadResult Method to get the first field of the first row of the result set from the database query.
public loadResultArray Method to get an array of values from the field in each row of the result set from the database query.
public loadRow Method to get the first row of the result set from the database query as an array.
public loadRowList Method to get an array of the result set rows from the database query where each row is an array.
public nameQuote Wrap an SQL statement identifier name such as field, table or database names in quotes to prevent injection risks and reserved word conflicts.
public query Execute the SQL statement.
public queryBatch Execute a query batch.
public quote Method to quote and optionally escape a string to database requirements for insertion into the database.
public select Select a database for use.
public setDebug Sets the database debugging state for the driver.
public setQuery Sets the SQL statement string for later execution.
public setUTF Set the connection to use UTF-8 character encoding.
public stderr Return the most recent error message for the database connector.
public transactionCommit Method to commit a transaction.
public transactionRollback Method to roll back a transaction.
public transactionStart Method to initialize a transaction.
public updateObject Updates a row in a table based on an object's properties.
public static getConnectors Get a list of available database connectors.
public static getInstance Method to return a instance based on the given options.
public static splitSql Splits a string of multiple queries into an array of individual queries.
public static test Test to see if the connector is available.
protected __construct Constructor.
protected fetchArray Method to fetch a row from the result set cursor as an array.
protected fetchAssoc Method to fetch a row from the result set cursor as an associative array.
protected fetchObject Method to fetch a row from the result set cursor as an object.
protected freeResult Method to free up the memory used for the result set.
protected replacePrefix This function replaces a string identifier with the string held is the class variable.

Importing

jimport( 'joomla.database.database' );

See also

[Edit See Also]

User contributed notes

<CodeExamplesForm />