API17

Difference between revisions of "JDatabase"

From Joomla! Documentation

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

Revision as of 20:00, 11 May 2013

The "API17" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Joomla 11.1 JDatabase[edit]

Description[edit]

Template:Description:JDatabase [Edit Descripton]

Methods[edit]

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[edit]

jimport( 'joomla.database.database' );

See also[edit]

Template:SeeAlso:JDatabase [Edit See Also]

User contributed notes[edit]

<CodeExamplesForm />