<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://docs.joomla.org/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://docs.joomla.org/api.php?action=feedcontributions&amp;user=Haydenyoung&amp;feedformat=atom</id>
		<title>Joomla! Documentation - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="http://docs.joomla.org/api.php?action=feedcontributions&amp;user=Haydenyoung&amp;feedformat=atom"/>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Special:Contributions/Haydenyoung"/>
		<updated>2013-05-23T16:20:44Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.19.3</generator>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5</id>
		<title>Accessing the database using JDatabase/2.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5"/>
				<updated>2012-11-20T17:08:08Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{underconstruction}}&lt;br /&gt;
&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object you need just two lines of code to get a result from the database in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.&lt;br /&gt;
&lt;br /&gt;
===The Connection===&lt;br /&gt;
&lt;br /&gt;
Joomla supports a generic interface for connecting to the database, hiding the intricacies of a specific database server from the Framework developer, thus making Joomla code easier to port from one platform to another.&lt;br /&gt;
&lt;br /&gt;
To obtain a database connection, use the [http://api.joomla.org/Joomla-Platform/JFactory.html#getDbo JFactory getDbo] static method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The getDbo method will return a reference to a high-level abstract class called [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html JDatabaseDriver]; the Joomla Framework hides the specifics of the database server, which is loaded dynamically by getDbo via Joomla's configuration file.&lt;br /&gt;
&lt;br /&gt;
Alternatively, if your class inherits from the JModel (or a decendent class) getDbo method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = $this-&amp;gt;getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{JVer|3.0}} users should note that the JModel class has been renamed JModelLegacy and will eventually be deprecated in favour of the class JModelBase. Therefore, any Joomla 3.0 core or extension code should use JFactory::getDbo() to obtain a database connection.&lt;br /&gt;
&lt;br /&gt;
===The Query===&lt;br /&gt;
&lt;br /&gt;
Joomla's database querying has changed since the new Joomla Framework was introduced  &amp;quot;query chaining&amp;quot; is now the recommended method for building database queries (although string queries are still supported).&lt;br /&gt;
&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&lt;br /&gt;
&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&lt;br /&gt;
&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source's query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer's source code. &lt;br /&gt;
&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from a Single Table====&lt;br /&gt;
&lt;br /&gt;
Below is an example of creating a database query using the JDatabaseQuery class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'));&lt;br /&gt;
$query-&amp;gt;from('#__user_profiles');&lt;br /&gt;
$query-&amp;gt;where('profile_key LIKE \'custom.%\'');&lt;br /&gt;
$query-&amp;gt;order('ordering ASC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query can also be chained to simplify further:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'))&lt;br /&gt;
    -&amp;gt;from('#__user_profiles')&lt;br /&gt;
    -&amp;gt;where('profile_key LIKE \'custom.%\'')&lt;br /&gt;
    -&amp;gt;order('ordering ASC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Chaining can become useful when queries become longer and more complex.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from Multiple Tables====&lt;br /&gt;
&lt;br /&gt;
Using the JDatabaseQuery's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#join join] methods, we can select records from multiple related tables. The generic &amp;quot;join&amp;quot; method takes two arguments; the join &amp;quot;type&amp;quot; (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with 'a'.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#innerJoin inner], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#leftJoin left], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#rightJoin right] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#outerJoin outer] joins.&lt;br /&gt;
&lt;br /&gt;
We can use multiple joins to query across more than two tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name', 'c.*', 'd.*'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;join('LEFT', '#__user_profiles AS c ON (b.id = c.user_id)')&lt;br /&gt;
    -&amp;gt;join('RIGHT', '#__categories AS d ON (a.catid = d.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice how chaining makes the source code much more readable for these longer queries.&lt;br /&gt;
&lt;br /&gt;
====Inserting a Record====&lt;br /&gt;
&lt;br /&gt;
=====Using SQL=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseQuery class provides a number of methods for building insert queries, the most common being [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#insert insert], [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabaseQuery.html#columns columns] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#values values].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Insert columns.&lt;br /&gt;
$columns = array('user_id', 'profile_key', 'profile_value', 'ordering');&lt;br /&gt;
&lt;br /&gt;
// Insert values.&lt;br /&gt;
$values = array(1001, $db-&amp;gt;quote('custom.message'), $db-&amp;gt;quote('Inserting a record using insert()'), 1);&lt;br /&gt;
&lt;br /&gt;
// Prepare the insert query.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;insert($db-&amp;gt;quoteName('#__user_profiles'))&lt;br /&gt;
    -&amp;gt;columns($db-&amp;gt;quoteName($columns))&lt;br /&gt;
    -&amp;gt;values(implode(',', $values));&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since Joomla 3.0 there has been a change in how the Joomla database class executes a query.&lt;br /&gt;
&lt;br /&gt;
When executing a query in the Joomla Framework 11.4 we use the JDatabase's [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabase.html#query query] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 2.5.&lt;br /&gt;
    $result = $db-&amp;gt;query();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Joomla Framework 12.1 and higher, we use the JDatabaseDriver's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html#execute execute] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 3.0.&lt;br /&gt;
    $result = $db-&amp;gt;execute();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since the phase out of PHP 4.x support, PHP's exception model has been widely implemented in the Joomla Framework. Therefore, we can wrap our database execution in a try...catch block to catch any unexpected database errors that may arise. Any database-specific errors will be thrown using an instance of the [http://api.joomla.org/Joomla-Platform/Database/JDatabaseException.html JDatabaseException] class although it is best practice to catch the generic Exception object from which JDatabaseException inherits.&lt;br /&gt;
&lt;br /&gt;
=====Using an Object=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver also class provides us with a convenience method for saving an object directly to the database allowing us to add a record to a table without writing a single line of SQL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Create and populate an object.&lt;br /&gt;
$profile = new stdClass();&lt;br /&gt;
$profile-&amp;gt;user_id = 1001;&lt;br /&gt;
$profile-&amp;gt;profile_key='custom.message';&lt;br /&gt;
$profile-&amp;gt;profile_value='Inserting a record using insertObject()';&lt;br /&gt;
$profile-&amp;gt;ordering=1;&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    // Insert the object into the user profile table.&lt;br /&gt;
    $result = JFactory::getDbo()-&amp;gt;insertObject('#__user_profiles', $profile);&lt;br /&gt;
catch (Exception $e) {&lt;br /&gt;
    // catch any errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice here that we do not need to escape the table name; the insertObject method does this for us.&lt;br /&gt;
&lt;br /&gt;
The insertObject method will throw a [http://php.net/manual/en/class.runtimeexception.php RuntimeException] if there is a problem inserting the record into the database table.&lt;br /&gt;
&lt;br /&gt;
We need to ensure that the record does not exist before attempting to insert it, so adding some kind of record check before executing the insertObject method would be recommended.&lt;br /&gt;
&lt;br /&gt;
====Updating a Record====&lt;br /&gt;
&lt;br /&gt;
=====Using SQL=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseQuery class also provides methods for building update queries, in particular [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#update update] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#set set]. We also reuse another method which we used when creating select statements, the where method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Fields to update.&lt;br /&gt;
$fields = array(&lt;br /&gt;
    'profile_value=\'Updating custom message for user 1001.\'',&lt;br /&gt;
    'ordering=2');&lt;br /&gt;
&lt;br /&gt;
// Conditions for which records should be updated.&lt;br /&gt;
$conditions = array(&lt;br /&gt;
    'user_id=42', &lt;br /&gt;
    'profile_key=\'custom.message\'');&lt;br /&gt;
&lt;br /&gt;
$query-&amp;gt;update($db-&amp;gt;quoteName('#__user_profiles'))-&amp;gt;set($fields)-&amp;gt;where($conditions);&lt;br /&gt;
&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    $result = $db-&amp;gt;query(); // Use $db-&amp;gt;execute() for Joomla 3.0.&lt;br /&gt;
catch (Exception $e) {&lt;br /&gt;
    // Catch the error.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====Using an Object =====&lt;br /&gt;
&lt;br /&gt;
Like insertObject, the JDatabaseDriver class provides a convenience method for updating an object.&lt;br /&gt;
&lt;br /&gt;
Below we will update our custom table with new values using an existing id primary key:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Create an object for the record we are going to update.&lt;br /&gt;
$object = new stdClass();&lt;br /&gt;
&lt;br /&gt;
// Must be a valid primary key value.&lt;br /&gt;
$object-&amp;gt;id = 1;&lt;br /&gt;
$object-&amp;gt;title = 'My Custom Record';&lt;br /&gt;
$object-&amp;gt;description = 'A custom record being updated in the database.';&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    // Update their details in the users table using id as the primary key.&lt;br /&gt;
    $result = JFactory::getDbo()-&amp;gt;updateObject('#__custom_table', $object, 'id');&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch the error.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just like insertObject, updateObject takes care of escaping table names for us.&lt;br /&gt;
&lt;br /&gt;
The updateObject method will throw a RuntimeException if there is a problem inserting the record into the database table.&lt;br /&gt;
&lt;br /&gt;
We need to ensure that the record already exists before attempting to update it, so we would probably add some kind of record check before executing the updateObject method.&lt;br /&gt;
&lt;br /&gt;
====Deleting a Record====&lt;br /&gt;
&lt;br /&gt;
Just as there are select, insert and update method calls, there is also a delete method for remove records from the database.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// delete all custom keys for user 1001.&lt;br /&gt;
$conditions = array(&lt;br /&gt;
    'user_id=1001', &lt;br /&gt;
    'profile_key LIKE \'custom.%\'');&lt;br /&gt;
&lt;br /&gt;
$query-&amp;gt;delete($db-&amp;gt;quoteName('#__user_profiles'));&lt;br /&gt;
$query-&amp;gt;where($conditions);&lt;br /&gt;
&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
   $result = $db-&amp;gt;query(); // $db-&amp;gt;execute(); for Joomla 3.0.&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
   // catch the error.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Transactions===&lt;br /&gt;
&lt;br /&gt;
The Joomla 12.1 Framework introduces SQL transactions (where supported) via the JDatabaseDriver's transactionStart, transactionCommit and transactionRollback. This supersedes the queryBatch method which was introduced in 11.1.&lt;br /&gt;
&lt;br /&gt;
IMPORTANT NOTE: Transactions can only be used against transaction-aware storage engine such as InnoDB (many tables in Joomla still use the MyISAM storage engine which cannot support transactions).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    $db-&amp;gt;transactionStart();&lt;br /&gt;
	&lt;br /&gt;
    $query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
    &lt;br /&gt;
    $values = array($db-&amp;gt;quote('TEST_CONSTANT'), $db-&amp;gt;quote('Custom'), $db-&amp;gt;quote('/path/to/translation.ini'));&lt;br /&gt;
    &lt;br /&gt;
    $query-&amp;gt;insert($db-&amp;gt;quoteName('#__overrider'));&lt;br /&gt;
    $query-&amp;gt;columns($db-&amp;gt;quoteName(array('constant', 'string', 'file')));&lt;br /&gt;
    $query-&amp;gt;values(implode(',',$values));&lt;br /&gt;
&lt;br /&gt;
    $db-&amp;gt;setQuery($query);&lt;br /&gt;
    $result = $db-&amp;gt;query();&lt;br /&gt;
&lt;br /&gt;
    $db-&amp;gt;transactionCommit();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    $db-&amp;gt;transactionRollback();&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Anything between the transactionStart and transactionCommit methods are not executed until transactionCommit is called. If an exception occurs, we can roll back the changes using the transactionRollback method. This allows us to return the database to the original state if a problem occurs even though we may execute a number of changes to the database's tables.&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5</id>
		<title>Accessing the database using JDatabase/2.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5"/>
				<updated>2012-11-20T16:50:50Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: Transactions.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object you need just two lines of code to get a result from the database in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.&lt;br /&gt;
&lt;br /&gt;
===The Connection===&lt;br /&gt;
&lt;br /&gt;
Joomla supports a generic interface for connecting to the database, hiding the intricacies of a specific database server from the Framework developer, thus making Joomla code easier to port from one platform to another.&lt;br /&gt;
&lt;br /&gt;
To obtain a database connection, use the [http://api.joomla.org/Joomla-Platform/JFactory.html#getDbo JFactory getDbo] static method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The getDbo method will return a reference to a high-level abstract class called [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html JDatabaseDriver]; the Joomla Framework hides the specifics of the database server, which is loaded dynamically by getDbo via Joomla's configuration file.&lt;br /&gt;
&lt;br /&gt;
Alternatively, if your class inherits from the JModel (or a decendent class) getDbo method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = $this-&amp;gt;getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{JVer|3.0}} users should note that the JModel class has been renamed JModelLegacy and will eventually be deprecated in favour of the class JModelBase. Therefore, any Joomla 3.0 core or extension code should use JFactory::getDbo() to obtain a database connection.&lt;br /&gt;
&lt;br /&gt;
===The Query===&lt;br /&gt;
&lt;br /&gt;
Joomla's database querying has changed since the new Joomla Framework was introduced  &amp;quot;query chaining&amp;quot; is now the recommended method for building database queries (although string queries are still supported).&lt;br /&gt;
&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&lt;br /&gt;
&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&lt;br /&gt;
&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source's query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer's source code. &lt;br /&gt;
&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from a Single Table====&lt;br /&gt;
&lt;br /&gt;
Below is an example of creating a database query using the JDatabaseQuery class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'));&lt;br /&gt;
$query-&amp;gt;from('#__user_profiles');&lt;br /&gt;
$query-&amp;gt;where('profile_key LIKE \'custom.%\'');&lt;br /&gt;
$query-&amp;gt;order('ordering ASC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query can also be chained to simplify further:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'))&lt;br /&gt;
    -&amp;gt;from('#__user_profiles')&lt;br /&gt;
    -&amp;gt;where('profile_key LIKE \'custom.%\'')&lt;br /&gt;
    -&amp;gt;order('ordering ASC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Chaining can become useful when queries become longer and more complex.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from Multiple Tables====&lt;br /&gt;
&lt;br /&gt;
Using the JDatabaseQuery's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#join join] methods, we can select records from multiple related tables. The generic &amp;quot;join&amp;quot; method takes two arguments; the join &amp;quot;type&amp;quot; (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with 'a'.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#innerJoin inner], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#leftJoin left], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#rightJoin right] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#outerJoin outer] joins.&lt;br /&gt;
&lt;br /&gt;
We can use multiple joins to query across more than two tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name', 'c.*', 'd.*'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;join('LEFT', '#__user_profiles AS c ON (b.id = c.user_id)')&lt;br /&gt;
    -&amp;gt;join('RIGHT', '#__categories AS d ON (a.catid = d.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice how chaining makes the source code much more readable for these longer queries.&lt;br /&gt;
&lt;br /&gt;
====Inserting a Record====&lt;br /&gt;
&lt;br /&gt;
=====Using SQL=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseQuery class provides a number of methods for building insert queries, the most common being [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#insert insert], [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabaseQuery.html#columns columns] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#values values].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Insert columns.&lt;br /&gt;
$columns = array('user_id', 'profile_key', 'profile_value', 'ordering');&lt;br /&gt;
&lt;br /&gt;
// Insert values.&lt;br /&gt;
$values = array(1001, $db-&amp;gt;quote('custom.message'), $db-&amp;gt;quote('Inserting a record using insert()'), 1);&lt;br /&gt;
&lt;br /&gt;
// Prepare the insert query.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;insert($db-&amp;gt;quoteName('#__user_profiles'))&lt;br /&gt;
    -&amp;gt;columns($db-&amp;gt;quoteName($columns))&lt;br /&gt;
    -&amp;gt;values(implode(',', $values));&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since Joomla 3.0 there has been a change in how the Joomla database class executes a query.&lt;br /&gt;
&lt;br /&gt;
When executing a query in the Joomla Framework 11.4 we use the JDatabase's [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabase.html#query query] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 2.5.&lt;br /&gt;
    $result = $db-&amp;gt;query();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Joomla Framework 12.1 and higher, we use the JDatabaseDriver's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html#execute execute] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 3.0.&lt;br /&gt;
    $result = $db-&amp;gt;execute();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since the phase out of PHP 4.x support, PHP's exception model has been widely implemented in the Joomla Framework. Therefore, we can wrap our database execution in a try...catch block to catch any unexpected database errors that may arise. Any database-specific errors will be thrown using an instance of the [http://api.joomla.org/Joomla-Platform/Database/JDatabaseException.html JDatabaseException] class although it is best practice to catch the generic Exception object from which JDatabaseException inherits.&lt;br /&gt;
&lt;br /&gt;
=====Using an Object=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver also class provides us with a convenience method for saving an object directly to the database allowing us to add a record to a table without writing a single line of SQL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Create and populate an object.&lt;br /&gt;
$profile = new stdClass();&lt;br /&gt;
$profile-&amp;gt;user_id = 1001;&lt;br /&gt;
$profile-&amp;gt;profile_key='custom.message';&lt;br /&gt;
$profile-&amp;gt;profile_value='Inserting a record using insertObject()';&lt;br /&gt;
$profile-&amp;gt;ordering=1;&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    // Insert the object into the user profile table.&lt;br /&gt;
    $result = JFactory::getDbo()-&amp;gt;insertObject('#__user_profiles', $profile);&lt;br /&gt;
catch (Exception $e) {&lt;br /&gt;
    // catch any errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice here that we do not need to escape the table name; the insertObject method does this for us.&lt;br /&gt;
&lt;br /&gt;
The insertObject method will throw a [http://php.net/manual/en/class.runtimeexception.php RuntimeException] if there is a problem inserting the record into the database table.&lt;br /&gt;
&lt;br /&gt;
We need to ensure that the record does not exist before attempting to insert it, so adding some kind of record check before executing the insertObject method would be recommended.&lt;br /&gt;
&lt;br /&gt;
====Updating a Record====&lt;br /&gt;
&lt;br /&gt;
=====Using SQL=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseQuery class also provides methods for building update queries, in particular [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#update update] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#set set]. We also reuse another method which we used when creating select statements, the where method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Fields to update.&lt;br /&gt;
$fields = array(&lt;br /&gt;
    'profile_value=\'Updating custom message for user 1001.\'',&lt;br /&gt;
    'ordering=2');&lt;br /&gt;
&lt;br /&gt;
// Conditions for which records should be updated.&lt;br /&gt;
$conditions = array(&lt;br /&gt;
    'user_id=42', &lt;br /&gt;
    'profile_key=\'custom.message\'');&lt;br /&gt;
&lt;br /&gt;
$query-&amp;gt;update($db-&amp;gt;quoteName('#__user_profiles'))-&amp;gt;set($fields)-&amp;gt;where($conditions);&lt;br /&gt;
&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    $result = $db-&amp;gt;query(); // Use $db-&amp;gt;execute() for Joomla 3.0.&lt;br /&gt;
catch (Exception $e) {&lt;br /&gt;
    // Catch the error.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====Using an Object =====&lt;br /&gt;
&lt;br /&gt;
Like insertObject, the JDatabaseDriver class provides a convenience method for updating an object.&lt;br /&gt;
&lt;br /&gt;
Below we will update our custom table with new values using an existing id primary key:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Create an object for the record we are going to update.&lt;br /&gt;
$object = new stdClass();&lt;br /&gt;
&lt;br /&gt;
// Must be a valid primary key value.&lt;br /&gt;
$object-&amp;gt;id = 1;&lt;br /&gt;
$object-&amp;gt;title = 'My Custom Record';&lt;br /&gt;
$object-&amp;gt;description = 'A custom record being updated in the database.';&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    // Update their details in the users table using id as the primary key.&lt;br /&gt;
    $result = JFactory::getDbo()-&amp;gt;updateObject('#__custom_table', $object, 'id');&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch the error.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just like insertObject, updateObject takes care of escaping table names for us.&lt;br /&gt;
&lt;br /&gt;
The updateObject method will throw a RuntimeException if there is a problem inserting the record into the database table.&lt;br /&gt;
&lt;br /&gt;
We need to ensure that the record already exists before attempting to update it, so we would probably add some kind of record check before executing the updateObject method.&lt;br /&gt;
&lt;br /&gt;
====Deleting a Record====&lt;br /&gt;
&lt;br /&gt;
Just as there are select, insert and update method calls, there is also a delete method for remove records from the database.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// delete all custom keys for user 1001.&lt;br /&gt;
$conditions = array(&lt;br /&gt;
    'user_id=1001', &lt;br /&gt;
    'profile_key LIKE \'custom.%\'');&lt;br /&gt;
&lt;br /&gt;
$query-&amp;gt;delete($db-&amp;gt;quoteName('#__user_profiles'));&lt;br /&gt;
$query-&amp;gt;where($conditions);&lt;br /&gt;
&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
   $result = $db-&amp;gt;query(); // $db-&amp;gt;execute(); for Joomla 3.0.&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
   // catch the error.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Transactions===&lt;br /&gt;
&lt;br /&gt;
The Joomla 12.1 Framework introduces SQL transactions (where supported) via the JDatabaseDriver's transactionStart, transactionCommit and transactionRollback. This supersedes the queryBatch method which was introduced in 11.1.&lt;br /&gt;
&lt;br /&gt;
IMPORTANT NOTE: Transactions can only be used against transaction-aware storage engine such as InnoDB (many tables in Joomla still use the MyISAM storage engine which cannot support transactions).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    $db-&amp;gt;transactionStart();&lt;br /&gt;
	&lt;br /&gt;
    $query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
    &lt;br /&gt;
    $values = array($db-&amp;gt;quote('TEST_CONSTANT'), $db-&amp;gt;quote('Custom'), $db-&amp;gt;quote('/path/to/translation.ini'));&lt;br /&gt;
    &lt;br /&gt;
    $query-&amp;gt;insert($db-&amp;gt;quoteName('#__overrider'));&lt;br /&gt;
    $query-&amp;gt;columns($db-&amp;gt;quoteName(array('constant', 'string', 'file')));&lt;br /&gt;
    $query-&amp;gt;values(implode(',',$values));&lt;br /&gt;
&lt;br /&gt;
    $db-&amp;gt;setQuery($query);&lt;br /&gt;
    $result = $db-&amp;gt;query();&lt;br /&gt;
&lt;br /&gt;
    $db-&amp;gt;transactionCommit();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    $db-&amp;gt;transactionRollback();&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Anything between the transactionStart and transactionCommit methods are not executed until transactionCommit is called. If an exception occurs, we can roll back the changes using the transactionRollback method. This allows us to return the database to the original state if a problem occurs even though we may execute a number of changes to the database's tables.&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5</id>
		<title>Accessing the database using JDatabase/2.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5"/>
				<updated>2012-11-20T15:21:29Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: /* Using SQL */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object you need just two lines of code to get a result from the database in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.&lt;br /&gt;
&lt;br /&gt;
===The Connection===&lt;br /&gt;
&lt;br /&gt;
Joomla supports a generic interface for connecting to the database, hiding the intricacies of a specific database server from the Framework developer, thus making Joomla code easier to port from one platform to another.&lt;br /&gt;
&lt;br /&gt;
To obtain a database connection, use the [http://api.joomla.org/Joomla-Platform/JFactory.html#getDbo JFactory getDbo] static method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The getDbo method will return a reference to a high-level abstract class called [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html JDatabaseDriver]; the Joomla Framework hides the specifics of the database server, which is loaded dynamically by getDbo via Joomla's configuration file.&lt;br /&gt;
&lt;br /&gt;
Alternatively, if your class inherits from the JModel (or a decendent class) getDbo method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = $this-&amp;gt;getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{JVer|3.0}} users should note that the JModel class has been renamed JModelLegacy and will eventually be deprecated in favour of the class JModelBase. Therefore, any Joomla 3.0 core or extension code should use JFactory::getDbo() to obtain a database connection.&lt;br /&gt;
&lt;br /&gt;
===The Query===&lt;br /&gt;
&lt;br /&gt;
Joomla's database querying has changed since the new Joomla Framework was introduced  &amp;quot;query chaining&amp;quot; is now the recommended method for building database queries (although string queries are still supported).&lt;br /&gt;
&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&lt;br /&gt;
&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&lt;br /&gt;
&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source's query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer's source code. &lt;br /&gt;
&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from a Single Table====&lt;br /&gt;
&lt;br /&gt;
Below is an example of creating a database query using the JDatabaseQuery class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'));&lt;br /&gt;
$query-&amp;gt;from('#__user_profiles');&lt;br /&gt;
$query-&amp;gt;where('profile_key LIKE \'custom.%\'');&lt;br /&gt;
$query-&amp;gt;order('ordering ASC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query can also be chained to simplify further:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'))&lt;br /&gt;
    -&amp;gt;from('#__user_profiles')&lt;br /&gt;
    -&amp;gt;where('profile_key LIKE \'custom.%\'')&lt;br /&gt;
    -&amp;gt;order('ordering ASC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Chaining can become useful when queries become longer and more complex.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from Multiple Tables====&lt;br /&gt;
&lt;br /&gt;
Using the JDatabaseQuery's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#join join] methods, we can select records from multiple related tables. The generic &amp;quot;join&amp;quot; method takes two arguments; the join &amp;quot;type&amp;quot; (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with 'a'.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#innerJoin inner], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#leftJoin left], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#rightJoin right] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#outerJoin outer] joins.&lt;br /&gt;
&lt;br /&gt;
We can use multiple joins to query across more than two tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name', 'c.*', 'd.*'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;join('LEFT', '#__user_profiles AS c ON (b.id = c.user_id)')&lt;br /&gt;
    -&amp;gt;join('RIGHT', '#__categories AS d ON (a.catid = d.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice how chaining makes the source code much more readable for these longer queries.&lt;br /&gt;
&lt;br /&gt;
====Inserting a Record====&lt;br /&gt;
&lt;br /&gt;
=====Using SQL=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseQuery class provides a number of methods for building insert queries, the most common being [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#insert insert], [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabaseQuery.html#columns columns] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#values values].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Insert columns.&lt;br /&gt;
$columns = array('user_id', 'profile_key', 'profile_value', 'ordering');&lt;br /&gt;
&lt;br /&gt;
// Insert values.&lt;br /&gt;
$values = array(1001, $db-&amp;gt;quote('custom.message'), $db-&amp;gt;quote('Inserting a record using insert()'), 1);&lt;br /&gt;
&lt;br /&gt;
// Prepare the insert query.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;insert($db-&amp;gt;quoteName('#__user_profiles'))&lt;br /&gt;
    -&amp;gt;columns($db-&amp;gt;quoteName($columns))&lt;br /&gt;
    -&amp;gt;values(implode(',', $values));&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since Joomla 3.0 there has been a change in how the Joomla database class executes a query.&lt;br /&gt;
&lt;br /&gt;
When executing a query in the Joomla Framework 11.4 we use the JDatabase's [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabase.html#query query] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 2.5.&lt;br /&gt;
    $result = $db-&amp;gt;query();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Joomla Framework 12.1 and higher, we use the JDatabaseDriver's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html#execute execute] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 3.0.&lt;br /&gt;
    $result = $db-&amp;gt;execute();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since the phase out of PHP 4.x support, PHP's exception model has been widely implemented in the Joomla Framework. Therefore, we can wrap our database execution in a try...catch block to catch any unexpected database errors that may arise. Any database-specific errors will be thrown using an instance of the [http://api.joomla.org/Joomla-Platform/Database/JDatabaseException.html JDatabaseException] class although it is best practice to catch the generic Exception object from which JDatabaseException inherits.&lt;br /&gt;
&lt;br /&gt;
=====Using an Object=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver also class provides us with a convenience method for saving an object directly to the database allowing us to add a record to a table without writing a single line of SQL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Create and populate an object.&lt;br /&gt;
$profile = new stdClass();&lt;br /&gt;
$profile-&amp;gt;user_id = 1001;&lt;br /&gt;
$profile-&amp;gt;profile_key='custom.message';&lt;br /&gt;
$profile-&amp;gt;profile_value='Inserting a record using insertObject()';&lt;br /&gt;
$profile-&amp;gt;ordering=1;&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    // Insert the object into the user profile table.&lt;br /&gt;
    $result = JFactory::getDbo()-&amp;gt;insertObject('#__user_profiles', $profile);&lt;br /&gt;
catch (Exception $e) {&lt;br /&gt;
    // catch any errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice here that we do not need to escape the table name; the insertObject method does this for us.&lt;br /&gt;
&lt;br /&gt;
The insertObject method will throw a [http://php.net/manual/en/class.runtimeexception.php RuntimeException] if there is a problem inserting the record into the database table.&lt;br /&gt;
&lt;br /&gt;
We need to ensure that the record does not exist before attempting to insert it, so adding some kind of record check before executing the insertObject method would be recommended.&lt;br /&gt;
&lt;br /&gt;
====Updating a Record====&lt;br /&gt;
&lt;br /&gt;
=====Using SQL=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseQuery class also provides methods for building update queries, in particular [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#update update] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#set set]. We also reuse another method which we used when creating select statements, the where method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Fields to update.&lt;br /&gt;
$fields = array(&lt;br /&gt;
    'profile_value=\'Updating custom message for user 1001.\'',&lt;br /&gt;
    'ordering=2');&lt;br /&gt;
&lt;br /&gt;
// Conditions for which records should be updated.&lt;br /&gt;
$conditions = array(&lt;br /&gt;
    'user_id=42', &lt;br /&gt;
    'profile_key=\'custom.message\'');&lt;br /&gt;
&lt;br /&gt;
$query-&amp;gt;update($db-&amp;gt;quoteName('#__user_profiles'))-&amp;gt;set($fields)-&amp;gt;where($conditions);&lt;br /&gt;
&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    $result = $db-&amp;gt;query(); // Use $db-&amp;gt;execute() for Joomla 3.0.&lt;br /&gt;
catch (Exception $e) {&lt;br /&gt;
    // Catch the error.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====Using an Object =====&lt;br /&gt;
&lt;br /&gt;
Like insertObject, the JDatabaseDriver class provides a convenience method for updating an object.&lt;br /&gt;
&lt;br /&gt;
Below we will update our custom table with new values using an existing id primary key:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Create an object for the record we are going to update.&lt;br /&gt;
$object = new stdClass();&lt;br /&gt;
&lt;br /&gt;
// Must be a valid primary key value.&lt;br /&gt;
$object-&amp;gt;id = 1;&lt;br /&gt;
$object-&amp;gt;title = 'My Custom Record';&lt;br /&gt;
$object-&amp;gt;description = 'A custom record being updated in the database.';&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    // Update their details in the users table using id as the primary key.&lt;br /&gt;
    $result = JFactory::getDbo()-&amp;gt;updateObject('#__custom_table', $object, 'id');&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch the error.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just like insertObject, updateObject takes care of escaping table names for us.&lt;br /&gt;
&lt;br /&gt;
The updateObject method will throw a RuntimeException if there is a problem inserting the record into the database table.&lt;br /&gt;
&lt;br /&gt;
We need to ensure that the record already exists before attempting to update it, so we would probably add some kind of record check before executing the updateObject method.&lt;br /&gt;
&lt;br /&gt;
====Deleting a Record====&lt;br /&gt;
&lt;br /&gt;
Just as there are select, insert and update method calls, there is also a delete method for remove records from the database.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// delete all custom keys for user 1001.&lt;br /&gt;
$conditions = array(&lt;br /&gt;
    'user_id=1001', &lt;br /&gt;
    'profile_key LIKE \'custom.%\'');&lt;br /&gt;
&lt;br /&gt;
$query-&amp;gt;delete($db-&amp;gt;quoteName('#__user_profiles'));&lt;br /&gt;
$query-&amp;gt;where($conditions);&lt;br /&gt;
&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
   $result = $db-&amp;gt;query(); // $db-&amp;gt;execute(); for Joomla 3.0.&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
   // catch the error.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5</id>
		<title>Accessing the database using JDatabase/2.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5"/>
				<updated>2012-11-20T15:21:00Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: /* Deleting a Record */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object you need just two lines of code to get a result from the database in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.&lt;br /&gt;
&lt;br /&gt;
===The Connection===&lt;br /&gt;
&lt;br /&gt;
Joomla supports a generic interface for connecting to the database, hiding the intricacies of a specific database server from the Framework developer, thus making Joomla code easier to port from one platform to another.&lt;br /&gt;
&lt;br /&gt;
To obtain a database connection, use the [http://api.joomla.org/Joomla-Platform/JFactory.html#getDbo JFactory getDbo] static method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The getDbo method will return a reference to a high-level abstract class called [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html JDatabaseDriver]; the Joomla Framework hides the specifics of the database server, which is loaded dynamically by getDbo via Joomla's configuration file.&lt;br /&gt;
&lt;br /&gt;
Alternatively, if your class inherits from the JModel (or a decendent class) getDbo method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = $this-&amp;gt;getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{JVer|3.0}} users should note that the JModel class has been renamed JModelLegacy and will eventually be deprecated in favour of the class JModelBase. Therefore, any Joomla 3.0 core or extension code should use JFactory::getDbo() to obtain a database connection.&lt;br /&gt;
&lt;br /&gt;
===The Query===&lt;br /&gt;
&lt;br /&gt;
Joomla's database querying has changed since the new Joomla Framework was introduced  &amp;quot;query chaining&amp;quot; is now the recommended method for building database queries (although string queries are still supported).&lt;br /&gt;
&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&lt;br /&gt;
&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&lt;br /&gt;
&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source's query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer's source code. &lt;br /&gt;
&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from a Single Table====&lt;br /&gt;
&lt;br /&gt;
Below is an example of creating a database query using the JDatabaseQuery class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'));&lt;br /&gt;
$query-&amp;gt;from('#__user_profiles');&lt;br /&gt;
$query-&amp;gt;where('profile_key LIKE \'custom.%\'');&lt;br /&gt;
$query-&amp;gt;order('ordering ASC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query can also be chained to simplify further:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'))&lt;br /&gt;
    -&amp;gt;from('#__user_profiles')&lt;br /&gt;
    -&amp;gt;where('profile_key LIKE \'custom.%\'')&lt;br /&gt;
    -&amp;gt;order('ordering ASC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Chaining can become useful when queries become longer and more complex.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from Multiple Tables====&lt;br /&gt;
&lt;br /&gt;
Using the JDatabaseQuery's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#join join] methods, we can select records from multiple related tables. The generic &amp;quot;join&amp;quot; method takes two arguments; the join &amp;quot;type&amp;quot; (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with 'a'.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#innerJoin inner], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#leftJoin left], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#rightJoin right] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#outerJoin outer] joins.&lt;br /&gt;
&lt;br /&gt;
We can use multiple joins to query across more than two tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name', 'c.*', 'd.*'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;join('LEFT', '#__user_profiles AS c ON (b.id = c.user_id)')&lt;br /&gt;
    -&amp;gt;join('RIGHT', '#__categories AS d ON (a.catid = d.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice how chaining makes the source code much more readable for these longer queries.&lt;br /&gt;
&lt;br /&gt;
====Inserting a Record====&lt;br /&gt;
&lt;br /&gt;
=====Using SQL=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseQuery class provides a number of methods for building insert queries, the most common being [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#insert insert], [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabaseQuery.html#columns columns] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#values values].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Insert columns.&lt;br /&gt;
$columns = array('user_id', 'profile_key', 'profile_value', 'ordering');&lt;br /&gt;
&lt;br /&gt;
// Insert values.&lt;br /&gt;
$values = array(1001, $db-&amp;gt;quote('custom.message'), $db-&amp;gt;quote('Inserting a record using insert()'), 1);&lt;br /&gt;
&lt;br /&gt;
// Prepare the insert query.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;insert($db-&amp;gt;quoteName('#__user_profiles'))&lt;br /&gt;
    -&amp;gt;columns($db-&amp;gt;quoteName($columns))&lt;br /&gt;
    -&amp;gt;values(implode(',', $values));&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since Joomla 3.0 there has been a change in how the Joomla database class executes a query.&lt;br /&gt;
&lt;br /&gt;
When executing a query in the Joomla Framework 11.4 we use the JDatabase's [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabase.html#query query] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 2.5.&lt;br /&gt;
    $result = $db-&amp;gt;query();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Joomla Framework 12.1 and higher, we use the JDatabaseDriver's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html#execute execute] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 3.0.&lt;br /&gt;
    $result = $db-&amp;gt;execute();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since the phase out of PHP 4.x support, PHP's exception model has been widely implemented in the Joomla Framework. Therefore, we can wrap our database execution in a try...catch block to catch any unexpected database errors that may arise. Any database-specific errors will be thrown using an instance of the [http://api.joomla.org/Joomla-Platform/Database/JDatabaseException.html JDatabaseException] class although it is best practice to catch the generic Exception object from which JDatabaseException inherits.&lt;br /&gt;
&lt;br /&gt;
=====Using an Object=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver also class provides us with a convenience method for saving an object directly to the database allowing us to add a record to a table without writing a single line of SQL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Create and populate an object.&lt;br /&gt;
$profile = new stdClass();&lt;br /&gt;
$profile-&amp;gt;user_id = 1001;&lt;br /&gt;
$profile-&amp;gt;profile_key='custom.message';&lt;br /&gt;
$profile-&amp;gt;profile_value='Inserting a record using insertObject()';&lt;br /&gt;
$profile-&amp;gt;ordering=1;&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    // Insert the object into the user profile table.&lt;br /&gt;
    $result = JFactory::getDbo()-&amp;gt;insertObject('#__user_profiles', $profile);&lt;br /&gt;
catch (Exception $e) {&lt;br /&gt;
    // catch any errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice here that we do not need to escape the table name; the insertObject method does this for us.&lt;br /&gt;
&lt;br /&gt;
The insertObject method will throw a [http://php.net/manual/en/class.runtimeexception.php RuntimeException] if there is a problem inserting the record into the database table.&lt;br /&gt;
&lt;br /&gt;
We need to ensure that the record does not exist before attempting to insert it, so adding some kind of record check before executing the insertObject method would be recommended.&lt;br /&gt;
&lt;br /&gt;
====Updating a Record====&lt;br /&gt;
&lt;br /&gt;
=====Using SQL=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseQuery class also provides methods for building update queries, in particular [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#update update] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#set set]. We also reuse another method which we used when creating select statements, the where method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Fields to update.&lt;br /&gt;
$fields = array(&lt;br /&gt;
    'profile_value=\'Updating custom message for user 1001.\'',&lt;br /&gt;
    'ordering=2');&lt;br /&gt;
&lt;br /&gt;
// Conditions for which records should be updated.&lt;br /&gt;
$conditions = array(&lt;br /&gt;
    'user_id=42', &lt;br /&gt;
    'profile_key=\'custom.message\'');&lt;br /&gt;
&lt;br /&gt;
$query-&amp;gt;update($db-&amp;gt;quoteName('#__user_profiles'))-&amp;gt;set($fields)-&amp;gt;where($conditions);&lt;br /&gt;
&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    $result = $db-&amp;gt;query();&lt;br /&gt;
catch (Exception $e) {&lt;br /&gt;
    // Catch the error.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====Using an Object =====&lt;br /&gt;
&lt;br /&gt;
Like insertObject, the JDatabaseDriver class provides a convenience method for updating an object.&lt;br /&gt;
&lt;br /&gt;
Below we will update our custom table with new values using an existing id primary key:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Create an object for the record we are going to update.&lt;br /&gt;
$object = new stdClass();&lt;br /&gt;
&lt;br /&gt;
// Must be a valid primary key value.&lt;br /&gt;
$object-&amp;gt;id = 1;&lt;br /&gt;
$object-&amp;gt;title = 'My Custom Record';&lt;br /&gt;
$object-&amp;gt;description = 'A custom record being updated in the database.';&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    // Update their details in the users table using id as the primary key.&lt;br /&gt;
    $result = JFactory::getDbo()-&amp;gt;updateObject('#__custom_table', $object, 'id');&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch the error.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just like insertObject, updateObject takes care of escaping table names for us.&lt;br /&gt;
&lt;br /&gt;
The updateObject method will throw a RuntimeException if there is a problem inserting the record into the database table.&lt;br /&gt;
&lt;br /&gt;
We need to ensure that the record already exists before attempting to update it, so we would probably add some kind of record check before executing the updateObject method.&lt;br /&gt;
&lt;br /&gt;
====Deleting a Record====&lt;br /&gt;
&lt;br /&gt;
Just as there are select, insert and update method calls, there is also a delete method for remove records from the database.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// delete all custom keys for user 1001.&lt;br /&gt;
$conditions = array(&lt;br /&gt;
    'user_id=1001', &lt;br /&gt;
    'profile_key LIKE \'custom.%\'');&lt;br /&gt;
&lt;br /&gt;
$query-&amp;gt;delete($db-&amp;gt;quoteName('#__user_profiles'));&lt;br /&gt;
$query-&amp;gt;where($conditions);&lt;br /&gt;
&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
   $result = $db-&amp;gt;query(); // $db-&amp;gt;execute(); for Joomla 3.0.&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
   // catch the error.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5</id>
		<title>Accessing the database using JDatabase/2.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5"/>
				<updated>2012-11-20T15:20:40Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: /* Deleting a Record */ Deleting records from the database.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object you need just two lines of code to get a result from the database in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.&lt;br /&gt;
&lt;br /&gt;
===The Connection===&lt;br /&gt;
&lt;br /&gt;
Joomla supports a generic interface for connecting to the database, hiding the intricacies of a specific database server from the Framework developer, thus making Joomla code easier to port from one platform to another.&lt;br /&gt;
&lt;br /&gt;
To obtain a database connection, use the [http://api.joomla.org/Joomla-Platform/JFactory.html#getDbo JFactory getDbo] static method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The getDbo method will return a reference to a high-level abstract class called [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html JDatabaseDriver]; the Joomla Framework hides the specifics of the database server, which is loaded dynamically by getDbo via Joomla's configuration file.&lt;br /&gt;
&lt;br /&gt;
Alternatively, if your class inherits from the JModel (or a decendent class) getDbo method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = $this-&amp;gt;getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{JVer|3.0}} users should note that the JModel class has been renamed JModelLegacy and will eventually be deprecated in favour of the class JModelBase. Therefore, any Joomla 3.0 core or extension code should use JFactory::getDbo() to obtain a database connection.&lt;br /&gt;
&lt;br /&gt;
===The Query===&lt;br /&gt;
&lt;br /&gt;
Joomla's database querying has changed since the new Joomla Framework was introduced  &amp;quot;query chaining&amp;quot; is now the recommended method for building database queries (although string queries are still supported).&lt;br /&gt;
&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&lt;br /&gt;
&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&lt;br /&gt;
&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source's query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer's source code. &lt;br /&gt;
&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from a Single Table====&lt;br /&gt;
&lt;br /&gt;
Below is an example of creating a database query using the JDatabaseQuery class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'));&lt;br /&gt;
$query-&amp;gt;from('#__user_profiles');&lt;br /&gt;
$query-&amp;gt;where('profile_key LIKE \'custom.%\'');&lt;br /&gt;
$query-&amp;gt;order('ordering ASC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query can also be chained to simplify further:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'))&lt;br /&gt;
    -&amp;gt;from('#__user_profiles')&lt;br /&gt;
    -&amp;gt;where('profile_key LIKE \'custom.%\'')&lt;br /&gt;
    -&amp;gt;order('ordering ASC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Chaining can become useful when queries become longer and more complex.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from Multiple Tables====&lt;br /&gt;
&lt;br /&gt;
Using the JDatabaseQuery's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#join join] methods, we can select records from multiple related tables. The generic &amp;quot;join&amp;quot; method takes two arguments; the join &amp;quot;type&amp;quot; (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with 'a'.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#innerJoin inner], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#leftJoin left], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#rightJoin right] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#outerJoin outer] joins.&lt;br /&gt;
&lt;br /&gt;
We can use multiple joins to query across more than two tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name', 'c.*', 'd.*'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;join('LEFT', '#__user_profiles AS c ON (b.id = c.user_id)')&lt;br /&gt;
    -&amp;gt;join('RIGHT', '#__categories AS d ON (a.catid = d.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice how chaining makes the source code much more readable for these longer queries.&lt;br /&gt;
&lt;br /&gt;
====Inserting a Record====&lt;br /&gt;
&lt;br /&gt;
=====Using SQL=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseQuery class provides a number of methods for building insert queries, the most common being [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#insert insert], [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabaseQuery.html#columns columns] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#values values].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Insert columns.&lt;br /&gt;
$columns = array('user_id', 'profile_key', 'profile_value', 'ordering');&lt;br /&gt;
&lt;br /&gt;
// Insert values.&lt;br /&gt;
$values = array(1001, $db-&amp;gt;quote('custom.message'), $db-&amp;gt;quote('Inserting a record using insert()'), 1);&lt;br /&gt;
&lt;br /&gt;
// Prepare the insert query.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;insert($db-&amp;gt;quoteName('#__user_profiles'))&lt;br /&gt;
    -&amp;gt;columns($db-&amp;gt;quoteName($columns))&lt;br /&gt;
    -&amp;gt;values(implode(',', $values));&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since Joomla 3.0 there has been a change in how the Joomla database class executes a query.&lt;br /&gt;
&lt;br /&gt;
When executing a query in the Joomla Framework 11.4 we use the JDatabase's [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabase.html#query query] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 2.5.&lt;br /&gt;
    $result = $db-&amp;gt;query();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Joomla Framework 12.1 and higher, we use the JDatabaseDriver's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html#execute execute] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 3.0.&lt;br /&gt;
    $result = $db-&amp;gt;execute();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since the phase out of PHP 4.x support, PHP's exception model has been widely implemented in the Joomla Framework. Therefore, we can wrap our database execution in a try...catch block to catch any unexpected database errors that may arise. Any database-specific errors will be thrown using an instance of the [http://api.joomla.org/Joomla-Platform/Database/JDatabaseException.html JDatabaseException] class although it is best practice to catch the generic Exception object from which JDatabaseException inherits.&lt;br /&gt;
&lt;br /&gt;
=====Using an Object=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver also class provides us with a convenience method for saving an object directly to the database allowing us to add a record to a table without writing a single line of SQL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Create and populate an object.&lt;br /&gt;
$profile = new stdClass();&lt;br /&gt;
$profile-&amp;gt;user_id = 1001;&lt;br /&gt;
$profile-&amp;gt;profile_key='custom.message';&lt;br /&gt;
$profile-&amp;gt;profile_value='Inserting a record using insertObject()';&lt;br /&gt;
$profile-&amp;gt;ordering=1;&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    // Insert the object into the user profile table.&lt;br /&gt;
    $result = JFactory::getDbo()-&amp;gt;insertObject('#__user_profiles', $profile);&lt;br /&gt;
catch (Exception $e) {&lt;br /&gt;
    // catch any errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice here that we do not need to escape the table name; the insertObject method does this for us.&lt;br /&gt;
&lt;br /&gt;
The insertObject method will throw a [http://php.net/manual/en/class.runtimeexception.php RuntimeException] if there is a problem inserting the record into the database table.&lt;br /&gt;
&lt;br /&gt;
We need to ensure that the record does not exist before attempting to insert it, so adding some kind of record check before executing the insertObject method would be recommended.&lt;br /&gt;
&lt;br /&gt;
====Updating a Record====&lt;br /&gt;
&lt;br /&gt;
=====Using SQL=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseQuery class also provides methods for building update queries, in particular [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#update update] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#set set]. We also reuse another method which we used when creating select statements, the where method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Fields to update.&lt;br /&gt;
$fields = array(&lt;br /&gt;
    'profile_value=\'Updating custom message for user 1001.\'',&lt;br /&gt;
    'ordering=2');&lt;br /&gt;
&lt;br /&gt;
// Conditions for which records should be updated.&lt;br /&gt;
$conditions = array(&lt;br /&gt;
    'user_id=42', &lt;br /&gt;
    'profile_key=\'custom.message\'');&lt;br /&gt;
&lt;br /&gt;
$query-&amp;gt;update($db-&amp;gt;quoteName('#__user_profiles'))-&amp;gt;set($fields)-&amp;gt;where($conditions);&lt;br /&gt;
&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    $result = $db-&amp;gt;query();&lt;br /&gt;
catch (Exception $e) {&lt;br /&gt;
    // Catch the error.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====Using an Object =====&lt;br /&gt;
&lt;br /&gt;
Like insertObject, the JDatabaseDriver class provides a convenience method for updating an object.&lt;br /&gt;
&lt;br /&gt;
Below we will update our custom table with new values using an existing id primary key:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Create an object for the record we are going to update.&lt;br /&gt;
$object = new stdClass();&lt;br /&gt;
&lt;br /&gt;
// Must be a valid primary key value.&lt;br /&gt;
$object-&amp;gt;id = 1;&lt;br /&gt;
$object-&amp;gt;title = 'My Custom Record';&lt;br /&gt;
$object-&amp;gt;description = 'A custom record being updated in the database.';&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    // Update their details in the users table using id as the primary key.&lt;br /&gt;
    $result = JFactory::getDbo()-&amp;gt;updateObject('#__custom_table', $object, 'id');&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch the error.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just like insertObject, updateObject takes care of escaping table names for us.&lt;br /&gt;
&lt;br /&gt;
The updateObject method will throw a RuntimeException if there is a problem inserting the record into the database table.&lt;br /&gt;
&lt;br /&gt;
We need to ensure that the record already exists before attempting to update it, so we would probably add some kind of record check before executing the updateObject method.&lt;br /&gt;
&lt;br /&gt;
====Deleting a Record====&lt;br /&gt;
&lt;br /&gt;
Just as there are select, insert and update method calls, there is also a delete method for remove records from the database.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// delete all custom keys for user 1001.&lt;br /&gt;
$conditions = array(&lt;br /&gt;
    'user_id=1001', &lt;br /&gt;
    'profile_key LIKE \'custom.%\'');&lt;br /&gt;
&lt;br /&gt;
$query-&amp;gt;delete($db-&amp;gt;quoteName('#__user_profiles'));&lt;br /&gt;
$query-&amp;gt;where($conditions);&lt;br /&gt;
&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
   $result = $db-&amp;gt;query(); // $db-&amp;gt;execute(); for Joomla 3.0.&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
   // catch the error.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5</id>
		<title>Accessing the database using JDatabase/2.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5"/>
				<updated>2012-11-20T14:22:17Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: /* Using updateObject */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object you need just two lines of code to get a result from the database in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.&lt;br /&gt;
&lt;br /&gt;
===The Connection===&lt;br /&gt;
&lt;br /&gt;
Joomla supports a generic interface for connecting to the database, hiding the intricacies of a specific database server from the Framework developer, thus making Joomla code easier to port from one platform to another.&lt;br /&gt;
&lt;br /&gt;
To obtain a database connection, use the [http://api.joomla.org/Joomla-Platform/JFactory.html#getDbo JFactory getDbo] static method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The getDbo method will return a reference to a high-level abstract class called [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html JDatabaseDriver]; the Joomla Framework hides the specifics of the database server, which is loaded dynamically by getDbo via Joomla's configuration file.&lt;br /&gt;
&lt;br /&gt;
Alternatively, if your class inherits from the JModel (or a decendent class) getDbo method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = $this-&amp;gt;getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{JVer|3.0}} users should note that the JModel class has been renamed JModelLegacy and will eventually be deprecated in favour of the class JModelBase. Therefore, any Joomla 3.0 core or extension code should use JFactory::getDbo() to obtain a database connection.&lt;br /&gt;
&lt;br /&gt;
===The Query===&lt;br /&gt;
&lt;br /&gt;
Joomla's database querying has changed since the new Joomla Framework was introduced  &amp;quot;query chaining&amp;quot; is now the recommended method for building database queries (although string queries are still supported).&lt;br /&gt;
&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&lt;br /&gt;
&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&lt;br /&gt;
&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source's query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer's source code. &lt;br /&gt;
&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from a Single Table====&lt;br /&gt;
&lt;br /&gt;
Below is an example of creating a database query using the JDatabaseQuery class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'));&lt;br /&gt;
$query-&amp;gt;from('#__user_profiles');&lt;br /&gt;
$query-&amp;gt;where('profile_key LIKE \'custom.%\'');&lt;br /&gt;
$query-&amp;gt;order('ordering ASC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query can also be chained to simplify further:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'))&lt;br /&gt;
    -&amp;gt;from('#__user_profiles')&lt;br /&gt;
    -&amp;gt;where('profile_key LIKE \'custom.%\'')&lt;br /&gt;
    -&amp;gt;order('ordering ASC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Chaining can become useful when queries become longer and more complex.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from Multiple Tables====&lt;br /&gt;
&lt;br /&gt;
Using the JDatabaseQuery's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#join join] methods, we can select records from multiple related tables. The generic &amp;quot;join&amp;quot; method takes two arguments; the join &amp;quot;type&amp;quot; (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with 'a'.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#innerJoin inner], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#leftJoin left], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#rightJoin right] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#outerJoin outer] joins.&lt;br /&gt;
&lt;br /&gt;
We can use multiple joins to query across more than two tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name', 'c.*', 'd.*'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;join('LEFT', '#__user_profiles AS c ON (b.id = c.user_id)')&lt;br /&gt;
    -&amp;gt;join('RIGHT', '#__categories AS d ON (a.catid = d.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice how chaining makes the source code much more readable for these longer queries.&lt;br /&gt;
&lt;br /&gt;
====Inserting a Record====&lt;br /&gt;
&lt;br /&gt;
=====Using SQL=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseQuery class provides a number of methods for building insert queries, the most common being [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#insert insert], [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabaseQuery.html#columns columns] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#values values].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Insert columns.&lt;br /&gt;
$columns = array('user_id', 'profile_key', 'profile_value', 'ordering');&lt;br /&gt;
&lt;br /&gt;
// Insert values.&lt;br /&gt;
$values = array(1001, $db-&amp;gt;quote('custom.message'), $db-&amp;gt;quote('Inserting a record using insert()'), 1);&lt;br /&gt;
&lt;br /&gt;
// Prepare the insert query.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;insert($db-&amp;gt;quoteName('#__user_profiles'))&lt;br /&gt;
    -&amp;gt;columns($db-&amp;gt;quoteName($columns))&lt;br /&gt;
    -&amp;gt;values(implode(',', $values));&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since Joomla 3.0 there has been a change in how the Joomla database class executes a query.&lt;br /&gt;
&lt;br /&gt;
When executing a query in the Joomla Framework 11.4 we use the JDatabase's [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabase.html#query query] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 2.5.&lt;br /&gt;
    $result = $db-&amp;gt;query();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Joomla Framework 12.1 and higher, we use the JDatabaseDriver's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html#execute execute] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 3.0.&lt;br /&gt;
    $result = $db-&amp;gt;execute();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since the phase out of PHP 4.x support, PHP's exception model has been widely implemented in the Joomla Framework. Therefore, we can wrap our database execution in a try...catch block to catch any unexpected database errors that may arise. Any database-specific errors will be thrown using an instance of the [http://api.joomla.org/Joomla-Platform/Database/JDatabaseException.html JDatabaseException] class although it is best practice to catch the generic Exception object from which JDatabaseException inherits.&lt;br /&gt;
&lt;br /&gt;
=====Using an Object=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver also class provides us with a convenience method for saving an object directly to the database allowing us to add a record to a table without writing a single line of SQL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Create and populate an object.&lt;br /&gt;
$profile = new stdClass();&lt;br /&gt;
$profile-&amp;gt;user_id = 1001;&lt;br /&gt;
$profile-&amp;gt;profile_key='custom.message';&lt;br /&gt;
$profile-&amp;gt;profile_value='Inserting a record using insertObject()';&lt;br /&gt;
$profile-&amp;gt;ordering=1;&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    // Insert the object into the user profile table.&lt;br /&gt;
    $result = JFactory::getDbo()-&amp;gt;insertObject('#__user_profiles', $profile);&lt;br /&gt;
catch (Exception $e) {&lt;br /&gt;
    // catch any errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice here that we do not need to escape the table name; the insertObject method does this for us.&lt;br /&gt;
&lt;br /&gt;
The insertObject method will throw a [http://php.net/manual/en/class.runtimeexception.php RuntimeException] if there is a problem inserting the record into the database table.&lt;br /&gt;
&lt;br /&gt;
We need to ensure that the record does not exist before attempting to insert it, so adding some kind of record check before executing the insertObject method would be recommended.&lt;br /&gt;
&lt;br /&gt;
====Updating a Record====&lt;br /&gt;
&lt;br /&gt;
=====Using SQL=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseQuery class also provides methods for building update queries, in particular [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#update update] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#set set]. We also reuse another method which we used when creating select statements, the where method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Fields to update.&lt;br /&gt;
$fields = array(&lt;br /&gt;
    'profile_value=\'Updating custom message for user 1001.\'',&lt;br /&gt;
    'ordering=2');&lt;br /&gt;
&lt;br /&gt;
// Conditions for which records should be updated.&lt;br /&gt;
$conditions = array(&lt;br /&gt;
    'user_id=42', &lt;br /&gt;
    'profile_key=\'custom.message\'');&lt;br /&gt;
&lt;br /&gt;
$query-&amp;gt;update($db-&amp;gt;quoteName('#__user_profiles'))-&amp;gt;set($fields)-&amp;gt;where($conditions);&lt;br /&gt;
&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    $result = $db-&amp;gt;query();&lt;br /&gt;
catch (Exception $e) {&lt;br /&gt;
    // Catch the error.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====Using an Object =====&lt;br /&gt;
&lt;br /&gt;
Like insertObject, the JDatabaseDriver class provides a convenience method for updating an object.&lt;br /&gt;
&lt;br /&gt;
Below we will update our custom table with new values using an existing id primary key:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Create an object for the record we are going to update.&lt;br /&gt;
$object = new stdClass();&lt;br /&gt;
&lt;br /&gt;
// Must be a valid primary key value.&lt;br /&gt;
$object-&amp;gt;id = 1;&lt;br /&gt;
$object-&amp;gt;title = 'My Custom Record';&lt;br /&gt;
$object-&amp;gt;description = 'A custom record being updated in the database.';&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    // Update their details in the users table using id as the primary key.&lt;br /&gt;
    $result = JFactory::getDbo()-&amp;gt;updateObject('#__custom_table', $object, 'id');&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch the error.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just like insertObject, updateObject takes care of escaping table names for us.&lt;br /&gt;
&lt;br /&gt;
The updateObject method will throw a RuntimeException if there is a problem inserting the record into the database table.&lt;br /&gt;
&lt;br /&gt;
We need to ensure that the record already exists before attempting to update it, so we would probably add some kind of record check before executing the updateObject method.&lt;br /&gt;
&lt;br /&gt;
====Deleting a Record====&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5</id>
		<title>Accessing the database using JDatabase/2.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5"/>
				<updated>2012-11-20T14:20:56Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: /* Using an Object */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object you need just two lines of code to get a result from the database in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.&lt;br /&gt;
&lt;br /&gt;
===The Connection===&lt;br /&gt;
&lt;br /&gt;
Joomla supports a generic interface for connecting to the database, hiding the intricacies of a specific database server from the Framework developer, thus making Joomla code easier to port from one platform to another.&lt;br /&gt;
&lt;br /&gt;
To obtain a database connection, use the [http://api.joomla.org/Joomla-Platform/JFactory.html#getDbo JFactory getDbo] static method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The getDbo method will return a reference to a high-level abstract class called [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html JDatabaseDriver]; the Joomla Framework hides the specifics of the database server, which is loaded dynamically by getDbo via Joomla's configuration file.&lt;br /&gt;
&lt;br /&gt;
Alternatively, if your class inherits from the JModel (or a decendent class) getDbo method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = $this-&amp;gt;getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{JVer|3.0}} users should note that the JModel class has been renamed JModelLegacy and will eventually be deprecated in favour of the class JModelBase. Therefore, any Joomla 3.0 core or extension code should use JFactory::getDbo() to obtain a database connection.&lt;br /&gt;
&lt;br /&gt;
===The Query===&lt;br /&gt;
&lt;br /&gt;
Joomla's database querying has changed since the new Joomla Framework was introduced  &amp;quot;query chaining&amp;quot; is now the recommended method for building database queries (although string queries are still supported).&lt;br /&gt;
&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&lt;br /&gt;
&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&lt;br /&gt;
&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source's query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer's source code. &lt;br /&gt;
&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from a Single Table====&lt;br /&gt;
&lt;br /&gt;
Below is an example of creating a database query using the JDatabaseQuery class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'));&lt;br /&gt;
$query-&amp;gt;from('#__user_profiles');&lt;br /&gt;
$query-&amp;gt;where('profile_key LIKE \'custom.%\'');&lt;br /&gt;
$query-&amp;gt;order('ordering ASC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query can also be chained to simplify further:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'))&lt;br /&gt;
    -&amp;gt;from('#__user_profiles')&lt;br /&gt;
    -&amp;gt;where('profile_key LIKE \'custom.%\'')&lt;br /&gt;
    -&amp;gt;order('ordering ASC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Chaining can become useful when queries become longer and more complex.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from Multiple Tables====&lt;br /&gt;
&lt;br /&gt;
Using the JDatabaseQuery's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#join join] methods, we can select records from multiple related tables. The generic &amp;quot;join&amp;quot; method takes two arguments; the join &amp;quot;type&amp;quot; (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with 'a'.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#innerJoin inner], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#leftJoin left], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#rightJoin right] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#outerJoin outer] joins.&lt;br /&gt;
&lt;br /&gt;
We can use multiple joins to query across more than two tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name', 'c.*', 'd.*'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;join('LEFT', '#__user_profiles AS c ON (b.id = c.user_id)')&lt;br /&gt;
    -&amp;gt;join('RIGHT', '#__categories AS d ON (a.catid = d.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice how chaining makes the source code much more readable for these longer queries.&lt;br /&gt;
&lt;br /&gt;
====Inserting a Record====&lt;br /&gt;
&lt;br /&gt;
=====Using SQL=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseQuery class provides a number of methods for building insert queries, the most common being [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#insert insert], [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabaseQuery.html#columns columns] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#values values].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Insert columns.&lt;br /&gt;
$columns = array('user_id', 'profile_key', 'profile_value', 'ordering');&lt;br /&gt;
&lt;br /&gt;
// Insert values.&lt;br /&gt;
$values = array(1001, $db-&amp;gt;quote('custom.message'), $db-&amp;gt;quote('Inserting a record using insert()'), 1);&lt;br /&gt;
&lt;br /&gt;
// Prepare the insert query.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;insert($db-&amp;gt;quoteName('#__user_profiles'))&lt;br /&gt;
    -&amp;gt;columns($db-&amp;gt;quoteName($columns))&lt;br /&gt;
    -&amp;gt;values(implode(',', $values));&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since Joomla 3.0 there has been a change in how the Joomla database class executes a query.&lt;br /&gt;
&lt;br /&gt;
When executing a query in the Joomla Framework 11.4 we use the JDatabase's [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabase.html#query query] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 2.5.&lt;br /&gt;
    $result = $db-&amp;gt;query();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Joomla Framework 12.1 and higher, we use the JDatabaseDriver's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html#execute execute] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 3.0.&lt;br /&gt;
    $result = $db-&amp;gt;execute();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since the phase out of PHP 4.x support, PHP's exception model has been widely implemented in the Joomla Framework. Therefore, we can wrap our database execution in a try...catch block to catch any unexpected database errors that may arise. Any database-specific errors will be thrown using an instance of the [http://api.joomla.org/Joomla-Platform/Database/JDatabaseException.html JDatabaseException] class although it is best practice to catch the generic Exception object from which JDatabaseException inherits.&lt;br /&gt;
&lt;br /&gt;
=====Using an Object=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver also class provides us with a convenience method for saving an object directly to the database allowing us to add a record to a table without writing a single line of SQL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Create and populate an object.&lt;br /&gt;
$profile = new stdClass();&lt;br /&gt;
$profile-&amp;gt;user_id = 1001;&lt;br /&gt;
$profile-&amp;gt;profile_key='custom.message';&lt;br /&gt;
$profile-&amp;gt;profile_value='Inserting a record using insertObject()';&lt;br /&gt;
$profile-&amp;gt;ordering=1;&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    // Insert the object into the user profile table.&lt;br /&gt;
    $result = JFactory::getDbo()-&amp;gt;insertObject('#__user_profiles', $profile);&lt;br /&gt;
catch (Exception $e) {&lt;br /&gt;
    // catch any errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice here that we do not need to escape the table name; the insertObject method does this for us.&lt;br /&gt;
&lt;br /&gt;
The insertObject method will throw a [http://php.net/manual/en/class.runtimeexception.php RuntimeException] if there is a problem inserting the record into the database table.&lt;br /&gt;
&lt;br /&gt;
We need to ensure that the record does not exist before attempting to insert it, so adding some kind of record check before executing the insertObject method would be recommended.&lt;br /&gt;
&lt;br /&gt;
====Updating a Record====&lt;br /&gt;
&lt;br /&gt;
=====Using SQL=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseQuery class also provides methods for building update queries, in particular [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#update update] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#set set]. We also reuse another method which we used when creating select statements, the where method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Fields to update.&lt;br /&gt;
$fields = array(&lt;br /&gt;
    'profile_value=\'Updating custom message for user 1001.\'',&lt;br /&gt;
    'ordering=2');&lt;br /&gt;
&lt;br /&gt;
// Conditions for which records should be updated.&lt;br /&gt;
$conditions = array(&lt;br /&gt;
    'user_id=42', &lt;br /&gt;
    'profile_key=\'custom.message\'');&lt;br /&gt;
&lt;br /&gt;
$query-&amp;gt;update($db-&amp;gt;quoteName('#__user_profiles'))-&amp;gt;set($fields)-&amp;gt;where($conditions);&lt;br /&gt;
&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    $result = $db-&amp;gt;query();&lt;br /&gt;
catch (Exception $e) {&lt;br /&gt;
    // Catch the error.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====Using updateObject=====&lt;br /&gt;
&lt;br /&gt;
Like insertObject, the JDatabaseDriver class provides a convenience method for updating an object.&lt;br /&gt;
&lt;br /&gt;
Below we will update our custom table with new values using an existing id primary key:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Create an object for the record we are going to update.&lt;br /&gt;
$object = new stdClass();&lt;br /&gt;
&lt;br /&gt;
// Must be a valid primary key value.&lt;br /&gt;
$object-&amp;gt;id = 1;&lt;br /&gt;
$object-&amp;gt;title = 'My Custom Record';&lt;br /&gt;
$object-&amp;gt;description = 'A custom record being updated in the database.';&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    // Update their details in the users table using id as the primary key.&lt;br /&gt;
    $result = JFactory::getDbo()-&amp;gt;updateObject('#__custom_table', $object, 'id');&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch the error.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We need to ensure that the record already exists before attempting to update it, so we would probably add some kind of record check before executing the updateObject method.&lt;br /&gt;
&lt;br /&gt;
====Deleting a Record====&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5</id>
		<title>Accessing the database using JDatabase/2.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5"/>
				<updated>2012-11-20T14:19:51Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: /* Updating a Record */ Updating a record using an object.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object you need just two lines of code to get a result from the database in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.&lt;br /&gt;
&lt;br /&gt;
===The Connection===&lt;br /&gt;
&lt;br /&gt;
Joomla supports a generic interface for connecting to the database, hiding the intricacies of a specific database server from the Framework developer, thus making Joomla code easier to port from one platform to another.&lt;br /&gt;
&lt;br /&gt;
To obtain a database connection, use the [http://api.joomla.org/Joomla-Platform/JFactory.html#getDbo JFactory getDbo] static method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The getDbo method will return a reference to a high-level abstract class called [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html JDatabaseDriver]; the Joomla Framework hides the specifics of the database server, which is loaded dynamically by getDbo via Joomla's configuration file.&lt;br /&gt;
&lt;br /&gt;
Alternatively, if your class inherits from the JModel (or a decendent class) getDbo method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = $this-&amp;gt;getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{JVer|3.0}} users should note that the JModel class has been renamed JModelLegacy and will eventually be deprecated in favour of the class JModelBase. Therefore, any Joomla 3.0 core or extension code should use JFactory::getDbo() to obtain a database connection.&lt;br /&gt;
&lt;br /&gt;
===The Query===&lt;br /&gt;
&lt;br /&gt;
Joomla's database querying has changed since the new Joomla Framework was introduced  &amp;quot;query chaining&amp;quot; is now the recommended method for building database queries (although string queries are still supported).&lt;br /&gt;
&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&lt;br /&gt;
&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&lt;br /&gt;
&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source's query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer's source code. &lt;br /&gt;
&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from a Single Table====&lt;br /&gt;
&lt;br /&gt;
Below is an example of creating a database query using the JDatabaseQuery class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'));&lt;br /&gt;
$query-&amp;gt;from('#__user_profiles');&lt;br /&gt;
$query-&amp;gt;where('profile_key LIKE \'custom.%\'');&lt;br /&gt;
$query-&amp;gt;order('ordering ASC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query can also be chained to simplify further:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'))&lt;br /&gt;
    -&amp;gt;from('#__user_profiles')&lt;br /&gt;
    -&amp;gt;where('profile_key LIKE \'custom.%\'')&lt;br /&gt;
    -&amp;gt;order('ordering ASC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Chaining can become useful when queries become longer and more complex.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from Multiple Tables====&lt;br /&gt;
&lt;br /&gt;
Using the JDatabaseQuery's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#join join] methods, we can select records from multiple related tables. The generic &amp;quot;join&amp;quot; method takes two arguments; the join &amp;quot;type&amp;quot; (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with 'a'.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#innerJoin inner], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#leftJoin left], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#rightJoin right] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#outerJoin outer] joins.&lt;br /&gt;
&lt;br /&gt;
We can use multiple joins to query across more than two tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name', 'c.*', 'd.*'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;join('LEFT', '#__user_profiles AS c ON (b.id = c.user_id)')&lt;br /&gt;
    -&amp;gt;join('RIGHT', '#__categories AS d ON (a.catid = d.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice how chaining makes the source code much more readable for these longer queries.&lt;br /&gt;
&lt;br /&gt;
====Inserting a Record====&lt;br /&gt;
&lt;br /&gt;
=====Using SQL=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseQuery class provides a number of methods for building insert queries, the most common being [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#insert insert], [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabaseQuery.html#columns columns] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#values values].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Insert columns.&lt;br /&gt;
$columns = array('user_id', 'profile_key', 'profile_value', 'ordering');&lt;br /&gt;
&lt;br /&gt;
// Insert values.&lt;br /&gt;
$values = array(1001, $db-&amp;gt;quote('custom.message'), $db-&amp;gt;quote('Inserting a record using insert()'), 1);&lt;br /&gt;
&lt;br /&gt;
// Prepare the insert query.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;insert($db-&amp;gt;quoteName('#__user_profiles'))&lt;br /&gt;
    -&amp;gt;columns($db-&amp;gt;quoteName($columns))&lt;br /&gt;
    -&amp;gt;values(implode(',', $values));&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since Joomla 3.0 there has been a change in how the Joomla database class executes a query.&lt;br /&gt;
&lt;br /&gt;
When executing a query in the Joomla Framework 11.4 we use the JDatabase's [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabase.html#query query] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 2.5.&lt;br /&gt;
    $result = $db-&amp;gt;query();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Joomla Framework 12.1 and higher, we use the JDatabaseDriver's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html#execute execute] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 3.0.&lt;br /&gt;
    $result = $db-&amp;gt;execute();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since the phase out of PHP 4.x support, PHP's exception model has been widely implemented in the Joomla Framework. Therefore, we can wrap our database execution in a try...catch block to catch any unexpected database errors that may arise. Any database-specific errors will be thrown using an instance of the [http://api.joomla.org/Joomla-Platform/Database/JDatabaseException.html JDatabaseException] class although it is best practice to catch the generic Exception object from which JDatabaseException inherits.&lt;br /&gt;
&lt;br /&gt;
=====Using an Object=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver also class provides us with a convenience method for saving an object directly to the database allowing us to add a record to a table without writing a single line of SQL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Create and populate an object.&lt;br /&gt;
$profile = new stdClass();&lt;br /&gt;
$profile-&amp;gt;user_id = 1001;&lt;br /&gt;
$profile-&amp;gt;profile_key='custom.message';&lt;br /&gt;
$profile-&amp;gt;profile_value='Inserting a record using insertObject()';&lt;br /&gt;
$profile-&amp;gt;ordering=1;&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    // Insert the object into the user profile table.&lt;br /&gt;
    $result = JFactory::getDbo()-&amp;gt;insertObject('#__user_profiles', $profile);&lt;br /&gt;
catch (Exception $e) {&lt;br /&gt;
    // catch any errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice here that we do not need to escape the table name; the insertObject method does this for us.&lt;br /&gt;
&lt;br /&gt;
The insertObject method will throw a [http://php.net/manual/en/class.runtimeexception.php RuntimeException] if there is a problem inserting the record into the database table.&lt;br /&gt;
&lt;br /&gt;
====Updating a Record====&lt;br /&gt;
&lt;br /&gt;
=====Using SQL=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseQuery class also provides methods for building update queries, in particular [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#update update] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#set set]. We also reuse another method which we used when creating select statements, the where method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Fields to update.&lt;br /&gt;
$fields = array(&lt;br /&gt;
    'profile_value=\'Updating custom message for user 1001.\'',&lt;br /&gt;
    'ordering=2');&lt;br /&gt;
&lt;br /&gt;
// Conditions for which records should be updated.&lt;br /&gt;
$conditions = array(&lt;br /&gt;
    'user_id=42', &lt;br /&gt;
    'profile_key=\'custom.message\'');&lt;br /&gt;
&lt;br /&gt;
$query-&amp;gt;update($db-&amp;gt;quoteName('#__user_profiles'))-&amp;gt;set($fields)-&amp;gt;where($conditions);&lt;br /&gt;
&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    $result = $db-&amp;gt;query();&lt;br /&gt;
catch (Exception $e) {&lt;br /&gt;
    // Catch the error.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====Using updateObject=====&lt;br /&gt;
&lt;br /&gt;
Like insertObject, the JDatabaseDriver class provides a convenience method for updating an object.&lt;br /&gt;
&lt;br /&gt;
Below we will update our custom table with new values using an existing id primary key:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Create an object for the record we are going to update.&lt;br /&gt;
$object = new stdClass();&lt;br /&gt;
&lt;br /&gt;
// Must be a valid primary key value.&lt;br /&gt;
$object-&amp;gt;id = 1;&lt;br /&gt;
$object-&amp;gt;title = 'My Custom Record';&lt;br /&gt;
$object-&amp;gt;description = 'A custom record being updated in the database.';&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    // Update their details in the users table using id as the primary key.&lt;br /&gt;
    $result = JFactory::getDbo()-&amp;gt;updateObject('#__custom_table', $object, 'id');&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch the error.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We need to ensure that the record already exists before attempting to update it, so we would probably add some kind of record check before executing the updateObject method.&lt;br /&gt;
&lt;br /&gt;
====Deleting a Record====&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5</id>
		<title>Accessing the database using JDatabase/2.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5"/>
				<updated>2012-11-20T10:54:24Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: /* Updating a Record */ Updating a record.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object you need just two lines of code to get a result from the database in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.&lt;br /&gt;
&lt;br /&gt;
===The Connection===&lt;br /&gt;
&lt;br /&gt;
Joomla supports a generic interface for connecting to the database, hiding the intricacies of a specific database server from the Framework developer, thus making Joomla code easier to port from one platform to another.&lt;br /&gt;
&lt;br /&gt;
To obtain a database connection, use the [http://api.joomla.org/Joomla-Platform/JFactory.html#getDbo JFactory getDbo] static method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The getDbo method will return a reference to a high-level abstract class called [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html JDatabaseDriver]; the Joomla Framework hides the specifics of the database server, which is loaded dynamically by getDbo via Joomla's configuration file.&lt;br /&gt;
&lt;br /&gt;
Alternatively, if your class inherits from the JModel (or a decendent class) getDbo method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = $this-&amp;gt;getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{JVer|3.0}} users should note that the JModel class has been renamed JModelLegacy and will eventually be deprecated in favour of the class JModelBase. Therefore, any Joomla 3.0 core or extension code should use JFactory::getDbo() to obtain a database connection.&lt;br /&gt;
&lt;br /&gt;
===The Query===&lt;br /&gt;
&lt;br /&gt;
Joomla's database querying has changed since the new Joomla Framework was introduced  &amp;quot;query chaining&amp;quot; is now the recommended method for building database queries (although string queries are still supported).&lt;br /&gt;
&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&lt;br /&gt;
&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&lt;br /&gt;
&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source's query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer's source code. &lt;br /&gt;
&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from a Single Table====&lt;br /&gt;
&lt;br /&gt;
Below is an example of creating a database query using the JDatabaseQuery class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'));&lt;br /&gt;
$query-&amp;gt;from('#__user_profiles');&lt;br /&gt;
$query-&amp;gt;where('profile_key LIKE \'custom.%\'');&lt;br /&gt;
$query-&amp;gt;order('ordering ASC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query can also be chained to simplify further:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'))&lt;br /&gt;
    -&amp;gt;from('#__user_profiles')&lt;br /&gt;
    -&amp;gt;where('profile_key LIKE \'custom.%\'')&lt;br /&gt;
    -&amp;gt;order('ordering ASC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Chaining can become useful when queries become longer and more complex.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from Multiple Tables====&lt;br /&gt;
&lt;br /&gt;
Using the JDatabaseQuery's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#join join] methods, we can select records from multiple related tables. The generic &amp;quot;join&amp;quot; method takes two arguments; the join &amp;quot;type&amp;quot; (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with 'a'.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#innerJoin inner], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#leftJoin left], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#rightJoin right] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#outerJoin outer] joins.&lt;br /&gt;
&lt;br /&gt;
We can use multiple joins to query across more than two tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name', 'c.*', 'd.*'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;join('LEFT', '#__user_profiles AS c ON (b.id = c.user_id)')&lt;br /&gt;
    -&amp;gt;join('RIGHT', '#__categories AS d ON (a.catid = d.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice how chaining makes the source code much more readable for these longer queries.&lt;br /&gt;
&lt;br /&gt;
====Inserting a Record====&lt;br /&gt;
&lt;br /&gt;
=====Using SQL=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseQuery class provides a number of methods for building insert queries, the most common being [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#insert insert], [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabaseQuery.html#columns columns] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#values values].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Insert columns.&lt;br /&gt;
$columns = array('user_id', 'profile_key', 'profile_value', 'ordering');&lt;br /&gt;
&lt;br /&gt;
// Insert values.&lt;br /&gt;
$values = array(1001, $db-&amp;gt;quote('custom.message'), $db-&amp;gt;quote('Inserting a record using insert()'), 1);&lt;br /&gt;
&lt;br /&gt;
// Prepare the insert query.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;insert($db-&amp;gt;quoteName('#__user_profiles'))&lt;br /&gt;
    -&amp;gt;columns($db-&amp;gt;quoteName($columns))&lt;br /&gt;
    -&amp;gt;values(implode(',', $values));&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since Joomla 3.0 there has been a change in how the Joomla database class executes a query.&lt;br /&gt;
&lt;br /&gt;
When executing a query in the Joomla Framework 11.4 we use the JDatabase's [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabase.html#query query] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 2.5.&lt;br /&gt;
    $result = $db-&amp;gt;query();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Joomla Framework 12.1 and higher, we use the JDatabaseDriver's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html#execute execute] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 3.0.&lt;br /&gt;
    $result = $db-&amp;gt;execute();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since the phase out of PHP 4.x support, PHP's exception model has been widely implemented in the Joomla Framework. Therefore, we can wrap our database execution in a try...catch block to catch any unexpected database errors that may arise. Any database-specific errors will be thrown using an instance of the [http://api.joomla.org/Joomla-Platform/Database/JDatabaseException.html JDatabaseException] class although it is best practice to catch the generic Exception object from which JDatabaseException inherits.&lt;br /&gt;
&lt;br /&gt;
=====Using an Object=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver also class provides us with a convenience method for saving an object directly to the database allowing us to add a record to a table without writing a single line of SQL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Create and populate an object.&lt;br /&gt;
$profile = new stdClass();&lt;br /&gt;
$profile-&amp;gt;user_id = 1001;&lt;br /&gt;
$profile-&amp;gt;profile_key='custom.message';&lt;br /&gt;
$profile-&amp;gt;profile_value='Inserting a record using insertObject()';&lt;br /&gt;
$profile-&amp;gt;ordering=1;&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    // Insert the object into the user profile table.&lt;br /&gt;
    $result = JFactory::getDbo()-&amp;gt;insertObject('#__user_profiles', $profile);&lt;br /&gt;
catch (Exception $e) {&lt;br /&gt;
    // catch any errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice here that we do not need to escape the table name; the insertObject method does this for us.&lt;br /&gt;
&lt;br /&gt;
The insertObject method will throw a [http://php.net/manual/en/class.runtimeexception.php RuntimeException] if there is a problem inserting the record into the database table.&lt;br /&gt;
&lt;br /&gt;
====Updating a Record====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseQuery class also provides methods for building update queries, in particular [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#update update] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#set set]. We also reuse another method which we used when creating select statements, the where method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Fields to update.&lt;br /&gt;
$fields = array(&lt;br /&gt;
    'profile_value=\'Updating custom message for user 1001.\'',&lt;br /&gt;
    'ordering=2');&lt;br /&gt;
&lt;br /&gt;
// Conditions for which records should be updated.&lt;br /&gt;
$conditions = array(&lt;br /&gt;
    'user_id=42', &lt;br /&gt;
    'profile_key=\'custom.message\'');&lt;br /&gt;
&lt;br /&gt;
$query-&amp;gt;update($db-&amp;gt;quoteName('#__user_profiles'))-&amp;gt;set($fields)-&amp;gt;where($conditions);&lt;br /&gt;
&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    $result = $db-&amp;gt;query();&lt;br /&gt;
catch (Exception $e) {&lt;br /&gt;
    // Catch the error.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Deleting a Record====&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5</id>
		<title>Accessing the database using JDatabase/2.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5"/>
				<updated>2012-11-20T08:43:33Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: /* Using an Object */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object you need just two lines of code to get a result from the database in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.&lt;br /&gt;
&lt;br /&gt;
===The Connection===&lt;br /&gt;
&lt;br /&gt;
Joomla supports a generic interface for connecting to the database, hiding the intricacies of a specific database server from the Framework developer, thus making Joomla code easier to port from one platform to another.&lt;br /&gt;
&lt;br /&gt;
To obtain a database connection, use the [http://api.joomla.org/Joomla-Platform/JFactory.html#getDbo JFactory getDbo] static method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The getDbo method will return a reference to a high-level abstract class called [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html JDatabaseDriver]; the Joomla Framework hides the specifics of the database server, which is loaded dynamically by getDbo via Joomla's configuration file.&lt;br /&gt;
&lt;br /&gt;
Alternatively, if your class inherits from the JModel (or a decendent class) getDbo method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = $this-&amp;gt;getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{JVer|3.0}} users should note that the JModel class has been renamed JModelLegacy and will eventually be deprecated in favour of the class JModelBase. Therefore, any Joomla 3.0 core or extension code should use JFactory::getDbo() to obtain a database connection.&lt;br /&gt;
&lt;br /&gt;
===The Query===&lt;br /&gt;
&lt;br /&gt;
Joomla's database querying has changed since the new Joomla Framework was introduced  &amp;quot;query chaining&amp;quot; is now the recommended method for building database queries (although string queries are still supported).&lt;br /&gt;
&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&lt;br /&gt;
&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&lt;br /&gt;
&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source's query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer's source code. &lt;br /&gt;
&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from a Single Table====&lt;br /&gt;
&lt;br /&gt;
Below is an example of creating a database query using the JDatabaseQuery class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'));&lt;br /&gt;
$query-&amp;gt;from('#__user_profiles');&lt;br /&gt;
$query-&amp;gt;where('profile_key LIKE \'custom.%\'');&lt;br /&gt;
$query-&amp;gt;order('ordering ASC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query can also be chained to simplify further:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'))&lt;br /&gt;
    -&amp;gt;from('#__user_profiles')&lt;br /&gt;
    -&amp;gt;where('profile_key LIKE \'custom.%\'')&lt;br /&gt;
    -&amp;gt;order('ordering ASC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Chaining can become useful when queries become longer and more complex.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from Multiple Tables====&lt;br /&gt;
&lt;br /&gt;
Using the JDatabaseQuery's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#join join] methods, we can select records from multiple related tables. The generic &amp;quot;join&amp;quot; method takes two arguments; the join &amp;quot;type&amp;quot; (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with 'a'.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#innerJoin inner], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#leftJoin left], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#rightJoin right] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#outerJoin outer] joins.&lt;br /&gt;
&lt;br /&gt;
We can use multiple joins to query across more than two tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name', 'c.*', 'd.*'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;join('LEFT', '#__user_profiles AS c ON (b.id = c.user_id)')&lt;br /&gt;
    -&amp;gt;join('RIGHT', '#__categories AS d ON (a.catid = d.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice how chaining makes the source code much more readable for these longer queries.&lt;br /&gt;
&lt;br /&gt;
====Inserting a Record====&lt;br /&gt;
&lt;br /&gt;
=====Using SQL=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseQuery class provides a number of methods for building insert queries, the most common being [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#insert insert], [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabaseQuery.html#columns columns] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#values values].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Insert columns.&lt;br /&gt;
$columns = array('user_id', 'profile_key', 'profile_value', 'ordering');&lt;br /&gt;
&lt;br /&gt;
// Insert values.&lt;br /&gt;
$values = array(1001, $db-&amp;gt;quote('custom.message'), $db-&amp;gt;quote('Inserting a record using insert()'), 1);&lt;br /&gt;
&lt;br /&gt;
// Prepare the insert query.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;insert($db-&amp;gt;quoteName('#__user_profiles'))&lt;br /&gt;
    -&amp;gt;columns($db-&amp;gt;quoteName($columns))&lt;br /&gt;
    -&amp;gt;values(implode(',', $values));&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since Joomla 3.0 there has been a change in how the Joomla database class executes a query.&lt;br /&gt;
&lt;br /&gt;
When executing a query in the Joomla Framework 11.4 we use the JDatabase's [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabase.html#query query] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 2.5.&lt;br /&gt;
    $result = $db-&amp;gt;query();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Joomla Framework 12.1 and higher, we use the JDatabaseDriver's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html#execute execute] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 3.0.&lt;br /&gt;
    $result = $db-&amp;gt;execute();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since the phase out of PHP 4.x support, PHP's exception model has been widely implemented in the Joomla Framework. Therefore, we can wrap our database execution in a try...catch block to catch any unexpected database errors that may arise. Any database-specific errors will be thrown using an instance of the [http://api.joomla.org/Joomla-Platform/Database/JDatabaseException.html JDatabaseException] class although it is best practice to catch the generic Exception object from which JDatabaseException inherits.&lt;br /&gt;
&lt;br /&gt;
=====Using an Object=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver also class provides us with a convenience method for saving an object directly to the database allowing us to add a record to a table without writing a single line of SQL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Create and populate an object.&lt;br /&gt;
$profile = new stdClass();&lt;br /&gt;
$profile-&amp;gt;user_id = 1001;&lt;br /&gt;
$profile-&amp;gt;profile_key='custom.message';&lt;br /&gt;
$profile-&amp;gt;profile_value='Inserting a record using insertObject()';&lt;br /&gt;
$profile-&amp;gt;ordering=1;&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    // Insert the object into the user profile table.&lt;br /&gt;
    $result = JFactory::getDbo()-&amp;gt;insertObject('#__user_profiles', $profile);&lt;br /&gt;
catch (Exception $e) {&lt;br /&gt;
    // catch any errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice here that we do not need to escape the table name; the insertObject method does this for us.&lt;br /&gt;
&lt;br /&gt;
The insertObject method will throw a [http://php.net/manual/en/class.runtimeexception.php RuntimeException] if there is a problem inserting the record into the database table.&lt;br /&gt;
&lt;br /&gt;
====Updating a Record====&lt;br /&gt;
&lt;br /&gt;
====Deleting a Record====&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5</id>
		<title>Accessing the database using JDatabase/2.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5"/>
				<updated>2012-11-20T08:37:35Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: /* Using an Object */ Added commenting.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object you need just two lines of code to get a result from the database in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.&lt;br /&gt;
&lt;br /&gt;
===The Connection===&lt;br /&gt;
&lt;br /&gt;
Joomla supports a generic interface for connecting to the database, hiding the intricacies of a specific database server from the Framework developer, thus making Joomla code easier to port from one platform to another.&lt;br /&gt;
&lt;br /&gt;
To obtain a database connection, use the [http://api.joomla.org/Joomla-Platform/JFactory.html#getDbo JFactory getDbo] static method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The getDbo method will return a reference to a high-level abstract class called [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html JDatabaseDriver]; the Joomla Framework hides the specifics of the database server, which is loaded dynamically by getDbo via Joomla's configuration file.&lt;br /&gt;
&lt;br /&gt;
Alternatively, if your class inherits from the JModel (or a decendent class) getDbo method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = $this-&amp;gt;getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{JVer|3.0}} users should note that the JModel class has been renamed JModelLegacy and will eventually be deprecated in favour of the class JModelBase. Therefore, any Joomla 3.0 core or extension code should use JFactory::getDbo() to obtain a database connection.&lt;br /&gt;
&lt;br /&gt;
===The Query===&lt;br /&gt;
&lt;br /&gt;
Joomla's database querying has changed since the new Joomla Framework was introduced  &amp;quot;query chaining&amp;quot; is now the recommended method for building database queries (although string queries are still supported).&lt;br /&gt;
&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&lt;br /&gt;
&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&lt;br /&gt;
&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source's query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer's source code. &lt;br /&gt;
&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from a Single Table====&lt;br /&gt;
&lt;br /&gt;
Below is an example of creating a database query using the JDatabaseQuery class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'));&lt;br /&gt;
$query-&amp;gt;from('#__user_profiles');&lt;br /&gt;
$query-&amp;gt;where('profile_key LIKE \'custom.%\'');&lt;br /&gt;
$query-&amp;gt;order('ordering ASC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query can also be chained to simplify further:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'))&lt;br /&gt;
    -&amp;gt;from('#__user_profiles')&lt;br /&gt;
    -&amp;gt;where('profile_key LIKE \'custom.%\'')&lt;br /&gt;
    -&amp;gt;order('ordering ASC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Chaining can become useful when queries become longer and more complex.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from Multiple Tables====&lt;br /&gt;
&lt;br /&gt;
Using the JDatabaseQuery's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#join join] methods, we can select records from multiple related tables. The generic &amp;quot;join&amp;quot; method takes two arguments; the join &amp;quot;type&amp;quot; (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with 'a'.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#innerJoin inner], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#leftJoin left], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#rightJoin right] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#outerJoin outer] joins.&lt;br /&gt;
&lt;br /&gt;
We can use multiple joins to query across more than two tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name', 'c.*', 'd.*'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;join('LEFT', '#__user_profiles AS c ON (b.id = c.user_id)')&lt;br /&gt;
    -&amp;gt;join('RIGHT', '#__categories AS d ON (a.catid = d.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice how chaining makes the source code much more readable for these longer queries.&lt;br /&gt;
&lt;br /&gt;
====Inserting a Record====&lt;br /&gt;
&lt;br /&gt;
=====Using SQL=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseQuery class provides a number of methods for building insert queries, the most common being [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#insert insert], [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabaseQuery.html#columns columns] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#values values].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Insert columns.&lt;br /&gt;
$columns = array('user_id', 'profile_key', 'profile_value', 'ordering');&lt;br /&gt;
&lt;br /&gt;
// Insert values.&lt;br /&gt;
$values = array(1001, $db-&amp;gt;quote('custom.message'), $db-&amp;gt;quote('Inserting a record using insert()'), 1);&lt;br /&gt;
&lt;br /&gt;
// Prepare the insert query.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;insert($db-&amp;gt;quoteName('#__user_profiles'))&lt;br /&gt;
    -&amp;gt;columns($db-&amp;gt;quoteName($columns))&lt;br /&gt;
    -&amp;gt;values(implode(',', $values));&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since Joomla 3.0 there has been a change in how the Joomla database class executes a query.&lt;br /&gt;
&lt;br /&gt;
When executing a query in the Joomla Framework 11.4 we use the JDatabase's [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabase.html#query query] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 2.5.&lt;br /&gt;
    $result = $db-&amp;gt;query();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Joomla Framework 12.1 and higher, we use the JDatabaseDriver's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html#execute execute] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 3.0.&lt;br /&gt;
    $result = $db-&amp;gt;execute();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since the phase out of PHP 4.x support, PHP's exception model has been widely implemented in the Joomla Framework. Therefore, we can wrap our database execution in a try...catch block to catch any unexpected database errors that may arise. Any database-specific errors will be thrown using an instance of the [http://api.joomla.org/Joomla-Platform/Database/JDatabaseException.html JDatabaseException] class although it is best practice to catch the generic Exception object from which JDatabaseException inherits.&lt;br /&gt;
&lt;br /&gt;
=====Using an Object=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver also class provides us with a convenience method for saving an object directly to the database allowing us to add a record to a table without writing a single line of SQL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Create and populate an object.&lt;br /&gt;
$profile = new stdClass();&lt;br /&gt;
$profile-&amp;gt;user_id = 42;&lt;br /&gt;
$profile-&amp;gt;profile_key='custom.message';&lt;br /&gt;
$profile-&amp;gt;profile_value='Inserting a record using insertObject()';&lt;br /&gt;
$profile-&amp;gt;ordering=1;&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    // Insert the object into the user profile table.&lt;br /&gt;
    $result = JFactory::getDbo()-&amp;gt;insertObject('#__user_profiles', $profile);&lt;br /&gt;
catch (Exception $e) {&lt;br /&gt;
    // catch any errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice here that we do not need to escape the table name; the insertObject method does this for us.&lt;br /&gt;
&lt;br /&gt;
The insertObject method will throw a [http://php.net/manual/en/class.runtimeexception.php RuntimeException] if there is a problem inserting the record into the database table.&lt;br /&gt;
&lt;br /&gt;
====Updating a Record====&lt;br /&gt;
&lt;br /&gt;
====Deleting a Record====&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5</id>
		<title>Accessing the database using JDatabase/2.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5"/>
				<updated>2012-11-20T08:32:45Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: /* Inserting a Record */ Inserting a record using insertObject.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object you need just two lines of code to get a result from the database in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.&lt;br /&gt;
&lt;br /&gt;
===The Connection===&lt;br /&gt;
&lt;br /&gt;
Joomla supports a generic interface for connecting to the database, hiding the intricacies of a specific database server from the Framework developer, thus making Joomla code easier to port from one platform to another.&lt;br /&gt;
&lt;br /&gt;
To obtain a database connection, use the [http://api.joomla.org/Joomla-Platform/JFactory.html#getDbo JFactory getDbo] static method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The getDbo method will return a reference to a high-level abstract class called [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html JDatabaseDriver]; the Joomla Framework hides the specifics of the database server, which is loaded dynamically by getDbo via Joomla's configuration file.&lt;br /&gt;
&lt;br /&gt;
Alternatively, if your class inherits from the JModel (or a decendent class) getDbo method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = $this-&amp;gt;getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{JVer|3.0}} users should note that the JModel class has been renamed JModelLegacy and will eventually be deprecated in favour of the class JModelBase. Therefore, any Joomla 3.0 core or extension code should use JFactory::getDbo() to obtain a database connection.&lt;br /&gt;
&lt;br /&gt;
===The Query===&lt;br /&gt;
&lt;br /&gt;
Joomla's database querying has changed since the new Joomla Framework was introduced  &amp;quot;query chaining&amp;quot; is now the recommended method for building database queries (although string queries are still supported).&lt;br /&gt;
&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&lt;br /&gt;
&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&lt;br /&gt;
&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source's query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer's source code. &lt;br /&gt;
&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from a Single Table====&lt;br /&gt;
&lt;br /&gt;
Below is an example of creating a database query using the JDatabaseQuery class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'));&lt;br /&gt;
$query-&amp;gt;from('#__user_profiles');&lt;br /&gt;
$query-&amp;gt;where('profile_key LIKE \'custom.%\'');&lt;br /&gt;
$query-&amp;gt;order('ordering ASC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query can also be chained to simplify further:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'))&lt;br /&gt;
    -&amp;gt;from('#__user_profiles')&lt;br /&gt;
    -&amp;gt;where('profile_key LIKE \'custom.%\'')&lt;br /&gt;
    -&amp;gt;order('ordering ASC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Chaining can become useful when queries become longer and more complex.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from Multiple Tables====&lt;br /&gt;
&lt;br /&gt;
Using the JDatabaseQuery's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#join join] methods, we can select records from multiple related tables. The generic &amp;quot;join&amp;quot; method takes two arguments; the join &amp;quot;type&amp;quot; (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with 'a'.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#innerJoin inner], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#leftJoin left], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#rightJoin right] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#outerJoin outer] joins.&lt;br /&gt;
&lt;br /&gt;
We can use multiple joins to query across more than two tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name', 'c.*', 'd.*'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;join('LEFT', '#__user_profiles AS c ON (b.id = c.user_id)')&lt;br /&gt;
    -&amp;gt;join('RIGHT', '#__categories AS d ON (a.catid = d.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice how chaining makes the source code much more readable for these longer queries.&lt;br /&gt;
&lt;br /&gt;
====Inserting a Record====&lt;br /&gt;
&lt;br /&gt;
=====Using SQL=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseQuery class provides a number of methods for building insert queries, the most common being [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#insert insert], [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabaseQuery.html#columns columns] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#values values].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Insert columns.&lt;br /&gt;
$columns = array('user_id', 'profile_key', 'profile_value', 'ordering');&lt;br /&gt;
&lt;br /&gt;
// Insert values.&lt;br /&gt;
$values = array(1001, $db-&amp;gt;quote('custom.message'), $db-&amp;gt;quote('Inserting a record using insert()'), 1);&lt;br /&gt;
&lt;br /&gt;
// Prepare the insert query.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;insert($db-&amp;gt;quoteName('#__user_profiles'))&lt;br /&gt;
    -&amp;gt;columns($db-&amp;gt;quoteName($columns))&lt;br /&gt;
    -&amp;gt;values(implode(',', $values));&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since Joomla 3.0 there has been a change in how the Joomla database class executes a query.&lt;br /&gt;
&lt;br /&gt;
When executing a query in the Joomla Framework 11.4 we use the JDatabase's [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabase.html#query query] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 2.5.&lt;br /&gt;
    $result = $db-&amp;gt;query();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Joomla Framework 12.1 and higher, we use the JDatabaseDriver's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html#execute execute] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 3.0.&lt;br /&gt;
    $result = $db-&amp;gt;execute();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since the phase out of PHP 4.x support, PHP's exception model has been widely implemented in the Joomla Framework. Therefore, we can wrap our database execution in a try...catch block to catch any unexpected database errors that may arise. Any database-specific errors will be thrown using an instance of the [http://api.joomla.org/Joomla-Platform/Database/JDatabaseException.html JDatabaseException] class although it is best practice to catch the generic Exception object from which JDatabaseException inherits.&lt;br /&gt;
&lt;br /&gt;
=====Using an Object=====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver also class provides us with a convenience method for saving an object directly to the database allowing us to add a record to a table without writing a single line of SQL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$profile = new stdClass();&lt;br /&gt;
$profile-&amp;gt;user_id = 42;&lt;br /&gt;
$profile-&amp;gt;profile_key='custom.message';&lt;br /&gt;
$profile-&amp;gt;profile_value='Inserting a record using insertObject()';&lt;br /&gt;
$profile-&amp;gt;ordering=1;&lt;br /&gt;
&lt;br /&gt;
try {&lt;br /&gt;
    $result = $db-&amp;gt;insertObject('#__user_profiles', $profile);&lt;br /&gt;
catch (Exception $e) {&lt;br /&gt;
    // catch any errors.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
The insertObject method will throw a PHP [http://php.net/manual/en/class.runtimeexception.php RuntimeException] if there is a problem inserting the record into the database table.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice here that we do not need to escape the table name; the insertObject method does this for us.&lt;br /&gt;
&lt;br /&gt;
====Updating a Record====&lt;br /&gt;
&lt;br /&gt;
====Deleting a Record====&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/3.1</id>
		<title>Accessing the database using JDatabase/3.1</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/3.1"/>
				<updated>2012-11-20T07:26:00Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: 3.0 documentation.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{underconstruction}}&lt;br /&gt;
&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object you need just two lines of code to get a result from the database in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.&lt;br /&gt;
&lt;br /&gt;
===The Connection===&lt;br /&gt;
&lt;br /&gt;
Joomla supports a generic interface for connecting to the database, hiding the intricacies of a specific database server from the Framework developer, thus making Joomla code easier to port from one platform to another.&lt;br /&gt;
&lt;br /&gt;
To obtain a database connection, use the [http://api.joomla.org/Joomla-Platform/JFactory.html#getDbo JFactory getDbo] static method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The getDbo method will return a reference to a high-level abstract class called [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html JDatabaseDriver]; the Joomla Framework hides the specifics of the database server, which is loaded dynamically by getDbo via Joomla's configuration file.&lt;br /&gt;
&lt;br /&gt;
Alternatively, if your class inherits from the JModel (or a decendent class) getDbo method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = $this-&amp;gt;getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{JVer|3.0}} users should note that the JModel class has been renamed JModelLegacy and will eventually be deprecated in favour of the class JModelBase. Therefore, any Joomla 3.0 core or extension code should use JFactory::getDbo() to obtain a database connection.&lt;br /&gt;
&lt;br /&gt;
===The Query===&lt;br /&gt;
&lt;br /&gt;
Joomla's database querying has changed since the new Joomla Framework was introduced  &amp;quot;query chaining&amp;quot; is now the recommended method for building database queries (although string queries are still supported).&lt;br /&gt;
&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&lt;br /&gt;
&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&lt;br /&gt;
&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source's query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer's source code. &lt;br /&gt;
&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from a Single Table====&lt;br /&gt;
&lt;br /&gt;
Below is an example of creating a database query using the JDatabaseQuery class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'));&lt;br /&gt;
$query-&amp;gt;from('#__user_profiles');&lt;br /&gt;
$query-&amp;gt;where('profile_key LIKE \'custom.%\'');&lt;br /&gt;
$query-&amp;gt;order('ordering ASC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query can also be chained to simplify further:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'))&lt;br /&gt;
    -&amp;gt;from('#__user_profiles')&lt;br /&gt;
    -&amp;gt;where('profile_key LIKE \'custom.%\'')&lt;br /&gt;
    -&amp;gt;order('ordering ASC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Chaining can become useful when queries become longer and more complex.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from Multiple Tables====&lt;br /&gt;
&lt;br /&gt;
Using the JDatabaseQuery's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#join join] methods, we can select records from multiple related tables. The generic &amp;quot;join&amp;quot; method takes two arguments; the join &amp;quot;type&amp;quot; (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with 'a'.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#innerJoin inner], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#leftJoin left], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#rightJoin right] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#outerJoin outer] joins.&lt;br /&gt;
&lt;br /&gt;
We can use multiple joins to query across more than two tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name', 'c.*', 'd.*'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;join('LEFT', '#__user_profiles AS c ON (b.id = c.user_id)')&lt;br /&gt;
    -&amp;gt;join('RIGHT', '#__categories AS d ON (a.catid = d.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice how chaining makes the source code much more readable for these longer queries.&lt;br /&gt;
&lt;br /&gt;
====Inserting a Record====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseQuery class provides a number of methods for building insert queries, the most common being [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#insert insert], [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabaseQuery.html#columns columns] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#values values].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Insert columns.&lt;br /&gt;
$columns = array('user_id', 'profile_key', 'profile_value', 'ordering');&lt;br /&gt;
&lt;br /&gt;
// Insert values.&lt;br /&gt;
$values = array(1001, $db-&amp;gt;quote('custom.message'), $db-&amp;gt;quote('Inserting a record using insert()'), 1);&lt;br /&gt;
&lt;br /&gt;
// Prepare the insert query.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;insert($db-&amp;gt;quoteName('#__user_profiles'))&lt;br /&gt;
    -&amp;gt;columns($db-&amp;gt;quoteName($columns))&lt;br /&gt;
    -&amp;gt;values(implode(',', $values));&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since Joomla 3.0 there has been a change in how the Joomla database class executes a query.&lt;br /&gt;
&lt;br /&gt;
When executing a query in the Joomla Framework 11.4 we use the JDatabase's [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabase.html#query query] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 2.5.&lt;br /&gt;
    $result = $db-&amp;gt;query();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Joomla Framework 12.1 and higher, we use the JDatabaseDriver's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html#execute execute] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 3.0.&lt;br /&gt;
    $result = $db-&amp;gt;execute();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since the phase out of PHP 4.x support, PHP's exception model has been widely implemented in the Joomla Framework. Therefore, we can wrap our database execution in a try...catch block to catch any unexpected database errors that may arise. Any database-specific errors will be thrown using an instance of the [http://api.joomla.org/Joomla-Platform/Database/JDatabaseException.html JDatabaseException] class although it is best practice to catch the generic Exception object from which JDatabaseException inherits.&lt;br /&gt;
&lt;br /&gt;
====Updating a Record====&lt;br /&gt;
&lt;br /&gt;
====Deleting a Record====&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5</id>
		<title>Accessing the database using JDatabase/2.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5"/>
				<updated>2012-11-20T06:33:03Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: /* Inserting a Record */ Inserting a record using a chained query.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object you need just two lines of code to get a result from the database in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.&lt;br /&gt;
&lt;br /&gt;
===The Connection===&lt;br /&gt;
&lt;br /&gt;
Joomla supports a generic interface for connecting to the database, hiding the intricacies of a specific database server from the Framework developer, thus making Joomla code easier to port from one platform to another.&lt;br /&gt;
&lt;br /&gt;
To obtain a database connection, use the [http://api.joomla.org/Joomla-Platform/JFactory.html#getDbo JFactory getDbo] static method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The getDbo method will return a reference to a high-level abstract class called [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html JDatabaseDriver]; the Joomla Framework hides the specifics of the database server, which is loaded dynamically by getDbo via Joomla's configuration file.&lt;br /&gt;
&lt;br /&gt;
Alternatively, if your class inherits from the JModel (or a decendent class) getDbo method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = $this-&amp;gt;getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{JVer|3.0}} users should note that the JModel class has been renamed JModelLegacy and will eventually be deprecated in favour of the class JModelBase. Therefore, any Joomla 3.0 core or extension code should use JFactory::getDbo() to obtain a database connection.&lt;br /&gt;
&lt;br /&gt;
===The Query===&lt;br /&gt;
&lt;br /&gt;
Joomla's database querying has changed since the new Joomla Framework was introduced  &amp;quot;query chaining&amp;quot; is now the recommended method for building database queries (although string queries are still supported).&lt;br /&gt;
&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&lt;br /&gt;
&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&lt;br /&gt;
&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source's query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer's source code. &lt;br /&gt;
&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from a Single Table====&lt;br /&gt;
&lt;br /&gt;
Below is an example of creating a database query using the JDatabaseQuery class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'));&lt;br /&gt;
$query-&amp;gt;from('#__user_profiles');&lt;br /&gt;
$query-&amp;gt;where('profile_key LIKE \'custom.%\'');&lt;br /&gt;
$query-&amp;gt;order('ordering ASC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query can also be chained to simplify further:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'))&lt;br /&gt;
    -&amp;gt;from('#__user_profiles')&lt;br /&gt;
    -&amp;gt;where('profile_key LIKE \'custom.%\'')&lt;br /&gt;
    -&amp;gt;order('ordering ASC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Chaining can become useful when queries become longer and more complex.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from Multiple Tables====&lt;br /&gt;
&lt;br /&gt;
Using the JDatabaseQuery's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#join join] methods, we can select records from multiple related tables. The generic &amp;quot;join&amp;quot; method takes two arguments; the join &amp;quot;type&amp;quot; (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with 'a'.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#innerJoin inner], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#leftJoin left], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#rightJoin right] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#outerJoin outer] joins.&lt;br /&gt;
&lt;br /&gt;
We can use multiple joins to query across more than two tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name', 'c.*', 'd.*'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;join('LEFT', '#__user_profiles AS c ON (b.id = c.user_id)')&lt;br /&gt;
    -&amp;gt;join('RIGHT', '#__categories AS d ON (a.catid = d.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice how chaining makes the source code much more readable for these longer queries.&lt;br /&gt;
&lt;br /&gt;
====Inserting a Record====&lt;br /&gt;
&lt;br /&gt;
The JDatabaseQuery class provides a number of methods for building insert queries, the most common being [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#insert insert], [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabaseQuery.html#columns columns] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#values values].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Insert columns.&lt;br /&gt;
$columns = array('user_id', 'profile_key', 'profile_value', 'ordering');&lt;br /&gt;
&lt;br /&gt;
// Insert values.&lt;br /&gt;
$values = array(1001, $db-&amp;gt;quote('custom.message'), $db-&amp;gt;quote('Inserting a record using insert()'), 1);&lt;br /&gt;
&lt;br /&gt;
// Prepare the insert query.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;insert($db-&amp;gt;quoteName('#__user_profiles'))&lt;br /&gt;
    -&amp;gt;columns($db-&amp;gt;quoteName($columns))&lt;br /&gt;
    -&amp;gt;values(implode(',', $values));&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since Joomla 3.0 there has been a change in how the Joomla database class executes a query.&lt;br /&gt;
&lt;br /&gt;
When executing a query in the Joomla Framework 11.4 we use the JDatabase's [http://api.joomla.org/11.4/Joomla-Platform/Database/JDatabase.html#query query] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 2.5.&lt;br /&gt;
    $result = $db-&amp;gt;query();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Joomla Framework 12.1 and higher, we use the JDatabaseDriver's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html#execute execute] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    // Execute the query in Joomla 3.0.&lt;br /&gt;
    $result = $db-&amp;gt;execute();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    // catch any database errors.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since the phase out of PHP 4.x support, PHP's exception model has been widely implemented in the Joomla Framework. Therefore, we can wrap our database execution in a try...catch block to catch any unexpected database errors that may arise. Any database-specific errors will be thrown using an instance of the [http://api.joomla.org/Joomla-Platform/Database/JDatabaseException.html JDatabaseException] class although it is best practice to catch the generic Exception object from which JDatabaseException inherits.&lt;br /&gt;
&lt;br /&gt;
====Updating a Record====&lt;br /&gt;
&lt;br /&gt;
====Deleting a Record====&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5</id>
		<title>Accessing the database using JDatabase/2.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5"/>
				<updated>2012-11-20T04:27:42Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: /* The Connection */ Links to various useful classes and methods.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object you need just two lines of code to get a result from the database in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.&lt;br /&gt;
&lt;br /&gt;
===The Connection===&lt;br /&gt;
&lt;br /&gt;
Joomla supports a generic interface for connecting to the database, hiding the intricacies of a specific database server from the Framework developer, thus making Joomla code easier to port from one platform to another.&lt;br /&gt;
&lt;br /&gt;
To obtain a database connection, use the [http://api.joomla.org/Joomla-Platform/JFactory.html#getDbo JFactory getDbo] static method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The getDbo method will return a reference to a high-level abstract class called [http://api.joomla.org/Joomla-Platform/Database/JDatabaseDriver.html JDatabaseDriver]; the Joomla Framework hides the specifics of the database server, which is loaded dynamically by getDbo via Joomla's configuration file.&lt;br /&gt;
&lt;br /&gt;
Alternatively, if your class inherits from the JModel (or a decendent class) getDbo method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = $this-&amp;gt;getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{JVer|3.0}} users should note that the JModel class has been renamed JModelLegacy and will eventually be deprecated in favour of the class JModelBase. Therefore, any Joomla 3.0 core or extension code should use JFactory::getDbo() to obtain a database connection.&lt;br /&gt;
&lt;br /&gt;
===The Query===&lt;br /&gt;
&lt;br /&gt;
Joomla's database querying has changed since the new Joomla Framework was introduced  &amp;quot;query chaining&amp;quot; is now the recommended method for building database queries (although string queries are still supported).&lt;br /&gt;
&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&lt;br /&gt;
&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&lt;br /&gt;
&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source's query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer's source code. &lt;br /&gt;
&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from a Single Table====&lt;br /&gt;
&lt;br /&gt;
Below is an example of creating a database query using the JDatabaseQuery class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'));&lt;br /&gt;
$query-&amp;gt;from('#__user_profiles');&lt;br /&gt;
$query-&amp;gt;where('profile_key LIKE \'custom.%\'');&lt;br /&gt;
$query-&amp;gt;order('ordering ASC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query can also be chained to simplify further:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'))&lt;br /&gt;
    -&amp;gt;from('#__user_profiles')&lt;br /&gt;
    -&amp;gt;where('profile_key LIKE \'custom.%\'')&lt;br /&gt;
    -&amp;gt;order('ordering ASC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Chaining can become useful when queries become longer and more complex.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from Multiple Tables====&lt;br /&gt;
&lt;br /&gt;
Using the JDatabaseQuery's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#join join] methods, we can select records from multiple related tables. The generic &amp;quot;join&amp;quot; method takes two arguments; the join &amp;quot;type&amp;quot; (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with 'a'.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#innerJoin inner], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#leftJoin left], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#rightJoin right] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#outerJoin outer] joins.&lt;br /&gt;
&lt;br /&gt;
We can use multiple joins to query across more than two tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name', 'c.*', 'd.*'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;join('LEFT', '#__user_profiles AS c ON (b.id = c.user_id)')&lt;br /&gt;
    -&amp;gt;join('RIGHT', '#__categories AS d ON (a.catid = d.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice how chaining makes the source code much more readable for these longer queries.&lt;br /&gt;
&lt;br /&gt;
====Inserting a Record====&lt;br /&gt;
&lt;br /&gt;
====Updating a Record====&lt;br /&gt;
&lt;br /&gt;
====Deleting a Record====&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5</id>
		<title>Accessing the database using JDatabase/2.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5"/>
				<updated>2012-11-20T04:13:13Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: /* Selecting Records from Multiple Tables */ Chaining a query with multiple joins.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object you need just two lines of code to get a result from the database in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.&lt;br /&gt;
&lt;br /&gt;
===The Connection===&lt;br /&gt;
&lt;br /&gt;
Joomla supports a generic interface for connecting to the database, hiding the intricacies of a specific database server from the Framework developer, thus making Joomla code easier to port from one database to another.&lt;br /&gt;
&lt;br /&gt;
To obtain a database connection, use the JFactory getDbo static method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, if your class inherits from the JModel (or a decendent class) getDbo method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = $this-&amp;gt;getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{JVer|3.0}} users should note that the JModel class has been renamed JModelLegacy and will eventually be deprecated in favour of the class JModelBase. Therefore, any Joomla 3.0 core or extension code should use JFactory::getDbo() to obtain a database connection.&lt;br /&gt;
&lt;br /&gt;
===The Query===&lt;br /&gt;
&lt;br /&gt;
Joomla's database querying has changed since the new Joomla Framework was introduced  &amp;quot;query chaining&amp;quot; is now the recommended method for building database queries (although string queries are still supported).&lt;br /&gt;
&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&lt;br /&gt;
&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&lt;br /&gt;
&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source's query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer's source code. &lt;br /&gt;
&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from a Single Table====&lt;br /&gt;
&lt;br /&gt;
Below is an example of creating a database query using the JDatabaseQuery class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'));&lt;br /&gt;
$query-&amp;gt;from('#__user_profiles');&lt;br /&gt;
$query-&amp;gt;where('profile_key LIKE \'custom.%\'');&lt;br /&gt;
$query-&amp;gt;order('ordering ASC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query can also be chained to simplify further:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'))&lt;br /&gt;
    -&amp;gt;from('#__user_profiles')&lt;br /&gt;
    -&amp;gt;where('profile_key LIKE \'custom.%\'')&lt;br /&gt;
    -&amp;gt;order('ordering ASC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Chaining can become useful when queries become longer and more complex.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from Multiple Tables====&lt;br /&gt;
&lt;br /&gt;
Using the JDatabaseQuery's [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#join join] methods, we can select records from multiple related tables. The generic &amp;quot;join&amp;quot; method takes two arguments; the join &amp;quot;type&amp;quot; (inner, outer, left, right) and the join condition. In the following example you will notice that we can use all of the keywords we would normally use if we were writing a native SQL query, including the AS keyword for aliasing tables and the ON keyword for creating relationships between tables. Also note that the table alias is used in all methods which reference table columns (I.e. select, where, order).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with 'a'.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The join method above enables us to query both the content and user tables, retrieving articles with their author details. There are also convenience methods for [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#innerJoin inner], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#leftJoin left], [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#rightJoin right] and [http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#outerJoin outer] joins.&lt;br /&gt;
&lt;br /&gt;
We can use multiple joins to query across more than two tables:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name', 'c.*', 'd.*'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;join('INNER', '#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;join('LEFT', '#__user_profiles AS c ON (b.id = c.user_id)')&lt;br /&gt;
    -&amp;gt;join('RIGHT', '#__categories AS d ON (a.catid = d.id)')&lt;br /&gt;
    -&amp;gt;where('b.username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('a.created DESC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice how chaining makes the source code much more readable for these longer queries.&lt;br /&gt;
&lt;br /&gt;
====Inserting a Record====&lt;br /&gt;
&lt;br /&gt;
====Updating a Record====&lt;br /&gt;
&lt;br /&gt;
====Deleting a Record====&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5</id>
		<title>Accessing the database using JDatabase/2.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5"/>
				<updated>2012-11-19T14:50:12Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: /* Selecting Records from Multiple Tables */ A chained multi-table query.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object you need just two lines of code to get a result from the database in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.&lt;br /&gt;
&lt;br /&gt;
===The Connection===&lt;br /&gt;
&lt;br /&gt;
Joomla supports a generic interface for connecting to the database, hiding the intricacies of a specific database server from the Framework developer, thus making Joomla code easier to port from one database to another.&lt;br /&gt;
&lt;br /&gt;
To obtain a database connection, use the JFactory getDbo static method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, if your class inherits from the JModel (or a decendent class) getDbo method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = $this-&amp;gt;getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{JVer|3.0}} users should note that the JModel class has been renamed JModelLegacy and will eventually be deprecated in favour of the class JModelBase. Therefore, any Joomla 3.0 core or extension code should use JFactory::getDbo() to obtain a database connection.&lt;br /&gt;
&lt;br /&gt;
===The Query===&lt;br /&gt;
&lt;br /&gt;
Joomla's database querying has changed since the new Joomla Framework was introduced  &amp;quot;query chaining&amp;quot; is now the recommended method for building database queries (although string queries are still supported).&lt;br /&gt;
&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&lt;br /&gt;
&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&lt;br /&gt;
&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source's query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer's source code. &lt;br /&gt;
&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from a Single Table====&lt;br /&gt;
&lt;br /&gt;
Below is an example of creating a database query using the JDatabaseQuery class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'));&lt;br /&gt;
$query-&amp;gt;from('#__user_profiles');&lt;br /&gt;
$query-&amp;gt;where('profile_key LIKE \'custom.%\'');&lt;br /&gt;
$query-&amp;gt;order('ordering ASC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query can also be chained to simplify further:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'))&lt;br /&gt;
    -&amp;gt;from('#__user_profiles')&lt;br /&gt;
    -&amp;gt;where('profile_key LIKE \'custom.%\'')&lt;br /&gt;
    -&amp;gt;order('ordering ASC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Chaining can become useful when queries become longer and more complex.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from Multiple Tables====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all articles for users who have a username which starts with 'a'.&lt;br /&gt;
// Order it by the created date.&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('a.*', 'b.username', 'b.name'))&lt;br /&gt;
    -&amp;gt;from('#__content AS a')&lt;br /&gt;
    -&amp;gt;innerJoin('#__users AS b ON (a.created_by = b.id)')&lt;br /&gt;
    -&amp;gt;where('username LIKE \'a%\'')&lt;br /&gt;
    -&amp;gt;order('created DESC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Inserting a Record====&lt;br /&gt;
&lt;br /&gt;
====Updating a Record====&lt;br /&gt;
&lt;br /&gt;
====Deleting a Record====&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5</id>
		<title>Accessing the database using JDatabase/2.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5"/>
				<updated>2012-11-19T13:54:24Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: /* Selecting Records from a Single Table */ Example of chaining.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object you need just two lines of code to get a result from the database in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.&lt;br /&gt;
&lt;br /&gt;
===The Connection===&lt;br /&gt;
&lt;br /&gt;
Joomla supports a generic interface for connecting to the database, hiding the intricacies of a specific database server from the Framework developer, thus making Joomla code easier to port from one database to another.&lt;br /&gt;
&lt;br /&gt;
To obtain a database connection, use the JFactory getDbo static method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, if your class inherits from the JModel (or a decendent class) getDbo method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = $this-&amp;gt;getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{JVer|3.0}} users should note that the JModel class has been renamed JModelLegacy and will eventually be deprecated in favour of the class JModelBase. Therefore, any Joomla 3.0 core or extension code should use JFactory::getDbo() to obtain a database connection.&lt;br /&gt;
&lt;br /&gt;
===The Query===&lt;br /&gt;
&lt;br /&gt;
Joomla's database querying has changed since the new Joomla Framework was introduced  &amp;quot;query chaining&amp;quot; is now the recommended method for building database queries (although string queries are still supported).&lt;br /&gt;
&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&lt;br /&gt;
&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&lt;br /&gt;
&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source's query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer's source code. &lt;br /&gt;
&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from a Single Table====&lt;br /&gt;
&lt;br /&gt;
Below is an example of creating a database query using the JDatabaseQuery class. Using the select, from, where and order methods, we can create queries which are flexible, easily readable and portable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'));&lt;br /&gt;
$query-&amp;gt;from('#__user_profiles');&lt;br /&gt;
$query-&amp;gt;where('profile_key LIKE \'custom.%\'');&lt;br /&gt;
$query-&amp;gt;order('ordering ASC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query can also be chained to simplify further:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query&lt;br /&gt;
    -&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'))&lt;br /&gt;
    -&amp;gt;from('#__user_profiles')&lt;br /&gt;
    -&amp;gt;where('profile_key LIKE \'custom.%\'')&lt;br /&gt;
    -&amp;gt;order('ordering ASC');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Chaining can become useful when queries become longer and more complex.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from Multiple Tables====&lt;br /&gt;
&lt;br /&gt;
====Inserting a Record====&lt;br /&gt;
&lt;br /&gt;
====Updating a Record====&lt;br /&gt;
&lt;br /&gt;
====Deleting a Record====&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5</id>
		<title>Accessing the database using JDatabase/2.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5"/>
				<updated>2012-11-19T12:35:14Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: /* Selecting Records from a Single Table */ Example of a simple query.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object you need just two lines of code to get a result from the database in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.&lt;br /&gt;
&lt;br /&gt;
===The Connection===&lt;br /&gt;
&lt;br /&gt;
Joomla supports a generic interface for connecting to the database, hiding the intricacies of a specific database server from the Framework developer, thus making Joomla code easier to port from one database to another.&lt;br /&gt;
&lt;br /&gt;
To obtain a database connection, use the JFactory getDbo static method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, if your class inherits from the JModel (or a decendent class) getDbo method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = $this-&amp;gt;getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{JVer|3.0}} users should note that the JModel class has been renamed JModelLegacy and will eventually be deprecated in favour of the class JModelBase. Therefore, any Joomla 3.0 core or extension code should use JFactory::getDbo() to obtain a database connection.&lt;br /&gt;
&lt;br /&gt;
===The Query===&lt;br /&gt;
&lt;br /&gt;
Joomla's database querying has changed since the new Joomla Framework was introduced  &amp;quot;query chaining&amp;quot; is now the recommended method for building database queries (although string queries are still supported).&lt;br /&gt;
&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&lt;br /&gt;
&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&lt;br /&gt;
&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source's query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer's source code. &lt;br /&gt;
&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from a Single Table====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a db connection.&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
// Create a new query object.&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&lt;br /&gt;
// Select all records from the user profile table where key begins with &amp;quot;custom.&amp;quot;.&lt;br /&gt;
// Order it by the ordering field.&lt;br /&gt;
$query-&amp;gt;select(array('user_id', 'profile_key', 'profile_value', 'ordering'));&lt;br /&gt;
$query-&amp;gt;from('#__user_profiles');&lt;br /&gt;
$query-&amp;gt;where('profile_key LIKE \'custom.%\'');&lt;br /&gt;
$query-&amp;gt;order('ordering ASC');&lt;br /&gt;
&lt;br /&gt;
// Reset the query using our newly populated query object.&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&lt;br /&gt;
// Load the results as a list of stdClass objects.&lt;br /&gt;
$results = $db-&amp;gt;loadObjectList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from Multiple Tables====&lt;br /&gt;
&lt;br /&gt;
====Inserting a Record====&lt;br /&gt;
&lt;br /&gt;
====Updating a Record====&lt;br /&gt;
&lt;br /&gt;
====Deleting a Record====&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5</id>
		<title>Accessing the database using JDatabase/2.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5"/>
				<updated>2012-11-16T14:04:00Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: /* The Query */ Introduction to query chaining.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object you need just two lines of code to get a result from the database in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.&lt;br /&gt;
&lt;br /&gt;
===The Connection===&lt;br /&gt;
&lt;br /&gt;
Joomla supports a generic interface for connecting to the database, hiding the intricacies of a specific database server from the Framework developer, thus making Joomla code easier to port from one database to another.&lt;br /&gt;
&lt;br /&gt;
To obtain a database connection, use the JFactory getDbo static method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, if your class inherits from the JModel (or a decendent class) getDbo method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = $this-&amp;gt;getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{JVer|3.0}} users should note that the JModel class has been renamed JModelLegacy and will eventually be deprecated in favour of the class JModelBase. Therefore, any Joomla 3.0 core or extension code should use JFactory::getDbo() to obtain a database connection.&lt;br /&gt;
&lt;br /&gt;
===The Query===&lt;br /&gt;
&lt;br /&gt;
Joomla's database querying has changed since the new Joomla Framework was introduced  &amp;quot;query chaining&amp;quot; is now the recommended method for building database queries (although string queries are still supported).&lt;br /&gt;
&lt;br /&gt;
Query chaining refers to a method of connecting a number of methods, one after the other, with each method returning an object that can support the next method, improving readability and simplifying code.&lt;br /&gt;
&lt;br /&gt;
To obtain a new instance of the JDatabaseQuery class we use the JDatabaseDriver getQuery method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&lt;br /&gt;
$query = $db-&amp;gt;getQuery(true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The JDatabaseDriver::getQuery takes an optional argument, $new, which can be true or false (the default being false).&lt;br /&gt;
&lt;br /&gt;
To query our data source we can call a number of JDatabaseQuery methods; these methods encapsulate the data source's query language (in most cases SQL), hiding query-specific syntax from the developer and increasing the portability of the developer's source code. &lt;br /&gt;
&lt;br /&gt;
Some of the more frequently used methods include; select, from, join, where and order. There are also methods such as insert, update and delete for modifying records in the data store. By chaining these and other method calls, you can create almost any query against your data store without compromising portability of your code.&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from a Single Table====&lt;br /&gt;
&lt;br /&gt;
====Selecting Records from Multiple Tables====&lt;br /&gt;
&lt;br /&gt;
====Inserting a Record====&lt;br /&gt;
&lt;br /&gt;
====Updating a Record====&lt;br /&gt;
&lt;br /&gt;
====Deleting a Record====&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5</id>
		<title>Accessing the database using JDatabase/2.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5"/>
				<updated>2012-11-16T06:21:30Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: /* Usage */ Connection usage.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
Joomla can use different kinds of SQL database systems and run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object you need just two lines of code to get a result from the database in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.&lt;br /&gt;
&lt;br /&gt;
===The Connection===&lt;br /&gt;
&lt;br /&gt;
Joomla supports a generic interface for connecting to the database, hiding the intricacies of a specific database server from the Framework developer, thus making Joomla code easier to port from one database to another.&lt;br /&gt;
&lt;br /&gt;
To obtain a database connection, use the JFactory getDbo static method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, if your class inherits from the JModel (or a decendent class) getDbo method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = $this-&amp;gt;getDbo();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{JVer|3.0}} users should note that the JModel class has been renamed JModelLegacy and will eventually be deprecated in favour of the class JModelBase. Therefore, any Joomla 3.0 core or extension code should use JFactory::getDbo() to obtain a database connection.&lt;br /&gt;
&lt;br /&gt;
===The Query===&lt;br /&gt;
&lt;br /&gt;
Joomla's database querying has changed since the new Joomla Framework was introduced  &amp;quot;query chaining&amp;quot; is now the recommended method for building database queries.&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase</id>
		<title>Accessing the database using JDatabase</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase"/>
				<updated>2012-11-16T05:17:00Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{underconstruction}}&lt;br /&gt;
&lt;br /&gt;
{{version/tutor|1.5,2.5,3.0}}{{multiversion|The '''{{PAGENAME}}''' Tutorial is available in these versions:-|version|pages=no}}&lt;br /&gt;
&lt;br /&gt;
==Supported Storage Connectors==&lt;br /&gt;
&lt;br /&gt;
The table below outlines the database and storage connectors available for Joomla! as well as which version of Joomla they became available in.&lt;br /&gt;
&lt;br /&gt;
To make a connector available in Joomla's installer or global configuration manager, you will need to ensure the PHP library is installed (E.g. for PHP5 and MySQL the php5-mysql library would need to be installed).&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Database &lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Joomla Versions&lt;br /&gt;
|-&lt;br /&gt;
| MySQL || {{JVer|1.5}}{{JVer|2.5}}{{JVer|3.0}}&lt;br /&gt;
|-&lt;br /&gt;
| Postgresql || {{JVer|3.0}}&lt;br /&gt;
|-&lt;br /&gt;
| Microsoft SQL Server || {{JVer|2.5}}{{JVer|3.0}}&lt;br /&gt;
|-&lt;br /&gt;
| Microsoft SQL Azure || {{JVer|2.5}}{{JVer|3.0}}&lt;br /&gt;
|-&lt;br /&gt;
| Oracle DB || {{JVer|3.0}}&lt;br /&gt;
|-&lt;br /&gt;
| SQL Lite || {{JVer|3.0}}&lt;br /&gt;
|-&lt;br /&gt;
| PHP Data Objects (PDO)* || {{JVer|3.0}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* PHP Data Objects is a database abstraction layer and is shipped with PHP 5.1+.&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5</id>
		<title>Accessing the database using JDatabase/2.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5"/>
				<updated>2012-10-28T03:54:51Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
===The Connection===&lt;br /&gt;
&lt;br /&gt;
===The Query===&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase</id>
		<title>Accessing the database using JDatabase</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase"/>
				<updated>2012-10-28T03:51:27Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: /* Supported Storage Connectors */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
&lt;br /&gt;
{{version/tutor|1.5,2.5,3.0}}{{multiversion|The '''{{PAGENAME}}''' Tutorial is available in these versions:-|version|pages=no}}&lt;br /&gt;
&lt;br /&gt;
==Supported Storage Connectors==&lt;br /&gt;
&lt;br /&gt;
The table below outlines the database and storage connectors available for Joomla! as well as which version of Joomla they became available in.&lt;br /&gt;
&lt;br /&gt;
To make a connector available in Joomla's installer or global configuration manager, you will need to ensure the PHP library is installed (E.g. for PHP5 and MySQL the php5-mysql library would need to be installed).&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Database &lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Joomla Versions&lt;br /&gt;
|-&lt;br /&gt;
| MySQL || {{JVer|1.5}}{{JVer|2.5}}{{JVer|3.0}}&lt;br /&gt;
|-&lt;br /&gt;
| Postgresql || {{JVer|3.0}}&lt;br /&gt;
|-&lt;br /&gt;
| Microsoft SQL Server || {{JVer|2.5}}{{JVer|3.0}}&lt;br /&gt;
|-&lt;br /&gt;
| Microsoft SQL Azure || {{JVer|2.5}}{{JVer|3.0}}&lt;br /&gt;
|-&lt;br /&gt;
| Oracle DB || {{JVer|3.0}}&lt;br /&gt;
|-&lt;br /&gt;
| SQL Lite || {{JVer|3.0}}&lt;br /&gt;
|-&lt;br /&gt;
| PHP Data Objects (PDO)* || {{JVer|3.0}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* PHP Data Objects is a database abstraction layer and is shipped with PHP 5.1+.&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase</id>
		<title>Accessing the database using JDatabase</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase"/>
				<updated>2012-10-28T03:48:48Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: Supported storage connectors.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
&lt;br /&gt;
{{version/tutor|1.5,2.5,3.0}}{{multiversion|The '''{{PAGENAME}}''' Tutorial is available in these versions:-|version|pages=no}}&lt;br /&gt;
&lt;br /&gt;
==Supported Storage Connectors==&lt;br /&gt;
&lt;br /&gt;
The table below outlines the database and storage connectors available for Joomla! as well as which version of Joomla they became available in.&lt;br /&gt;
&lt;br /&gt;
To make a connector available in Joomla's installer or global configuration manager, you will need to ensure the PHP library is installed (E.g. for PHP5 and MySQL the php5-mysql library would need to be installed).&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Database &lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Joomla Versions&lt;br /&gt;
|-&lt;br /&gt;
| MySQL || {{JVer|1.5}}{{JVer|2.5}}{{JVer|3.0}}&lt;br /&gt;
|-&lt;br /&gt;
| Postgresql || {{JVer|3.0}}&lt;br /&gt;
|-&lt;br /&gt;
| Microsoft SQL Server || {{JVer|2.5}}{{JVer|3.0}}&lt;br /&gt;
|-&lt;br /&gt;
| Microsoft SQL Azure || {{JVer|2.5}}{{JVer|3.0}}&lt;br /&gt;
|-&lt;br /&gt;
| Oracle DB || {{JVer|3.0}}&lt;br /&gt;
|-&lt;br /&gt;
| SQL Lite || {{JVer|3.0}}&lt;br /&gt;
|-&lt;br /&gt;
| PHP Data Objects (PDO) || {{JVer|3.0}}&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5</id>
		<title>Accessing the database using JDatabase/2.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5"/>
				<updated>2012-10-28T03:17:50Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{inuse}&lt;br /&gt;
&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
===The Connection===&lt;br /&gt;
&lt;br /&gt;
===The Query===&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5</id>
		<title>Accessing the database using JDatabase/2.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5"/>
				<updated>2012-10-28T03:17:33Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: New 2.5/3.0 page for database connections and query chaining.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. New versions of the Joomla Platform API provide additional functionality which extends the database layer further, and includes features such as connectors to a greater variety of database servers and the query chaining to improve readability of connection code and simplify SQL coding.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
===The Connection===&lt;br /&gt;
&lt;br /&gt;
===The Query===&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase</id>
		<title>Accessing the database using JDatabase</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase"/>
				<updated>2012-10-28T02:16:27Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: Multiple versions of this tutorial are now available.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
&lt;br /&gt;
{{version/tutor|1.5,2.5,3.0}}{{multiversion|The '''{{PAGENAME}}''' Tutorial is available in these versions:-|version|pages=no}}&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/1.5</id>
		<title>Accessing the database using JDatabase/1.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/1.5"/>
				<updated>2012-10-28T02:12:16Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{underconstruction}}&lt;br /&gt;
&lt;br /&gt;
{{version|1.5|test}}Though most of this article still works on 1.5+, some improved ways need to be specified here or in a version specific copy of this article.&amp;lt;hr/&amp;gt;&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. This guide will help you use this layer.&lt;br /&gt;
&lt;br /&gt;
==Why should I use the Joomla database class?==&lt;br /&gt;
Joomla can use different kinds of SQL database systems and run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object you need just two lines of code to get a result from the database in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.&lt;br /&gt;
&lt;br /&gt;
==Preparing the query==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a database object&lt;br /&gt;
$db = JFactory::getDBO();&lt;br /&gt;
&lt;br /&gt;
$query = &amp;quot;SELECT * FROM #__example_table WHERE id = 999999;&amp;quot;;&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First we instantiate the database object; then we prepare the query. You can use the normal SQL syntax. The only thing you have to change is the table prefix. To make this as flexible as possible, Joomla uses a placeholder for the prefix, the &amp;amp;ldquo;#__&amp;amp;rdquo;. In the next step, the $db-&amp;gt;setQuery(), this string is replaced with the correct prefix.&lt;br /&gt;
&lt;br /&gt;
Now, if we don't want to get information from the database, but rather insert a row into it, we need one more function. Every string value in the SQL syntax should be quoted. For example, MySQL uses backticks &amp;amp;#096;&amp;amp;#096; for names and single quotes &amp;amp;lsquo;&amp;amp;lsquo; for values. Joomla has some functions to do this for us and to ensure code compatibility between different databases. We can pass the names to the function $db-&amp;gt;nameQuote($name) and the values to the function $db-&amp;gt;Quote($value). &lt;br /&gt;
&lt;br /&gt;
A fully quoted query example is:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = &amp;quot;&lt;br /&gt;
  SELECT * &lt;br /&gt;
    FROM &amp;quot;.$db-&amp;gt;nameQuote('#__example_table').&amp;quot;  &lt;br /&gt;
    WHERE &amp;quot;.$db-&amp;gt;nameQuote('id').&amp;quot; = &amp;quot;.$db-&amp;gt;quote('999999').&amp;quot;;&lt;br /&gt;
  &amp;quot;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whatever we want to do, we have to set the query with the $db-&amp;gt;setQuery() function. Although you could write the query directly as a parameter for $db-&amp;gt;setQuery(), it's commonly done by first saving it in a variable, normally $query, and then handing this variable over. This results in clean, readable code.&lt;br /&gt;
&lt;br /&gt;
==== setQuery($query) ====&lt;br /&gt;
The ''setQuery($query)'' method sets up a database query for later execution either by the query() method or one of the Load result methods.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDBO();&lt;br /&gt;
$query = &amp;quot;/* some valid sql string */&amp;quot;;&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
The parameter $query must be a valid SQL string. It can either be added as a string parameter or as a variable. Generally a variable is preferred; it leads to more legible code and can help in debugging.&lt;br /&gt;
&lt;br /&gt;
setQuery() also takes three other parameters: $offset, $limit (both used in list pagination) and $prefix, an alternative table prefix. All three variables have default values set and can usually be ignored.&lt;br /&gt;
&lt;br /&gt;
==Executing the Query==&lt;br /&gt;
To execute the query, Joomla provides several functions, which differ in their return value.&lt;br /&gt;
&lt;br /&gt;
=== Basic Query Execution ===&lt;br /&gt;
==== query() ====&lt;br /&gt;
The ''query()'' method is the basic tool for executing SQL queries on a database. In Joomla it is most often used for updating or administering the database simply because the various load methods detailed on this page have the query step built into them.&lt;br /&gt;
&lt;br /&gt;
The syntax is very straightforward:&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;$db = JFactory::getDBO();&lt;br /&gt;
$query = &amp;quot;/* some valid sql string */&amp;quot;;&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$result = $db-&amp;gt;query();&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: $query() returns an appropriate database resource if successful, or FALSE if not.&lt;br /&gt;
&lt;br /&gt;
=== Query Execution Information ===&lt;br /&gt;
* getAffectedRows()&lt;br /&gt;
* explain()&lt;br /&gt;
&lt;br /&gt;
==== insertid() ====&lt;br /&gt;
If you insert a record into a table that contains an AUTO_INCREMENT column, you can obtain the value stored into that column by calling the insertid() function&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
$query = &amp;quot;INSERT INTO '#__example_table' ('name','email','username')&lt;br /&gt;
        VALUES ('John Smith','johnsmith@domain.example','johnsmith')&amp;quot;;&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$db-&amp;gt;query();&lt;br /&gt;
$user_id = $db-&amp;gt;insertid();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Insert Query Execution ===&lt;br /&gt;
* insertObject()&lt;br /&gt;
&lt;br /&gt;
==Query Results ==&lt;br /&gt;
The database class contains many methods for working with a query's result set.&lt;br /&gt;
&lt;br /&gt;
=== Single Value Result ===&lt;br /&gt;
==== loadResult() ====&lt;br /&gt;
Use '''loadResult()''' when you expect just a single value back from your database query. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! id !! name !! email !! username&lt;br /&gt;
|- &lt;br /&gt;
| 1 || style=&amp;quot;background:yellow&amp;quot; | John Smith || johnsmith@domain.example || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@domain.example || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This is often the result of a 'count' query to get a number of records:&lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
$db = JFactory::getDBO();&lt;br /&gt;
$query = &amp;quot;&lt;br /&gt;
  SELECT COUNT(*)&lt;br /&gt;
    FROM &amp;quot;.$db-&amp;gt;nameQuote('#__my_table').&amp;quot;&lt;br /&gt;
    WHERE &amp;quot;.$db-&amp;gt;nameQuote('name').&amp;quot; = &amp;quot;.$db-&amp;gt;quote($value).&amp;quot;;&lt;br /&gt;
  &amp;quot;;&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$count = $db-&amp;gt;loadResult();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or where you are just looking for a single field from a single row of the table (or possibly a single field from the first row returned).&lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
$db = JFactory::getDBO();&lt;br /&gt;
$query = &amp;quot;&lt;br /&gt;
  SELECT &amp;quot;.$db-&amp;gt;nameQuote('field_name').&amp;quot;&lt;br /&gt;
    FROM &amp;quot;.$db-&amp;gt;nameQuote('#__my_table').&amp;quot;&lt;br /&gt;
    WHERE &amp;quot;.$db-&amp;gt;nameQuote('some_name').&amp;quot; = &amp;quot;.$db-&amp;gt;quote($some_value).&amp;quot;;&lt;br /&gt;
  &amp;quot;;&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$result = $db-&amp;gt;loadResult();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Single Row Results ===&lt;br /&gt;
Each of these results functions will return a single record from the database even though there may be several records that meet the criteria that you have set. To get more records you need to call the function again.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! id !! name !! email !! username&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 1 || John Smith || johnsmith@domain.example || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@domain.example || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== loadRow() ====&lt;br /&gt;
loadRow() returns an indexed array from a single record in the table: &lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$row = $db-&amp;gt;loadRow();&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give:&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( [0] =&amp;gt; 1 [1] =&amp;gt; John Smith [2] =&amp;gt; johnsmith@domain.example [3] =&amp;gt; johnsmith ) &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual values by using:&amp;lt;pre&amp;gt;$row['index'] // e.g. $row['2']&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
# The array indices are numeric starting from zero.&lt;br /&gt;
# Whilst you can repeat the call to get further rows, one of the functions that returns multiple rows might be more useful.&lt;br /&gt;
&lt;br /&gt;
==== loadAssoc() ====&lt;br /&gt;
loadAssoc() returns an associated array from a single record in the table: &lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$row = $db-&amp;gt;loadAssoc();&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give:&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( [id] =&amp;gt; 1 [name] =&amp;gt; John Smith [email] =&amp;gt; johnsmith@domain.example [username] =&amp;gt; johnsmith )&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual values by using:&amp;lt;pre&amp;gt;$row['name'] // e.g. $row['name']&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
# Whilst you can repeat the call to get further rows, one of the functions that returns multiple rows might be more useful.&lt;br /&gt;
&lt;br /&gt;
==== loadObject() ====&lt;br /&gt;
loadObject returns a PHP object from a single record in the table: &lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$result = $db-&amp;gt;loadObject();&lt;br /&gt;
print_r($result);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give:&lt;br /&gt;
&amp;lt;pre&amp;gt;stdClass Object ( [id] =&amp;gt; 1 [name] =&amp;gt; John Smith [email] =&amp;gt; johnsmith@domain.example [username] =&amp;gt; johnsmith )&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual values by using:&amp;lt;pre&amp;gt;$result-&amp;gt;index // e.g. $result-&amp;gt;email&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
# Whilst you can repeat the call to get further rows, one of the functions that returns multiple rows might be more useful.&lt;br /&gt;
&lt;br /&gt;
===Single Column Results ===&lt;br /&gt;
Each of these results functions will return a single column from the database. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! id !! name !! email !! username&lt;br /&gt;
|- &lt;br /&gt;
| 1 || style=&amp;quot;background:yellow&amp;quot; | John Smith || johnsmith@domain.example || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || style=&amp;quot;background:yellow&amp;quot; | Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || style=&amp;quot;background:yellow&amp;quot; | Yvonne de Gaulle || ydg@domain.example || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== loadResultArray() ====&lt;br /&gt;
loadResultArray() returns an indexed array from a single column in the table: &lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
$query = &amp;quot;&lt;br /&gt;
  SELECT name, email, username&lt;br /&gt;
    FROM . . . &amp;quot;;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$column= $db-&amp;gt;loadResultArray();&lt;br /&gt;
print_r($column);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give:&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( [0] =&amp;gt; John Smith [1] =&amp;gt; Magda Hellman [2] =&amp;gt; Yvonne de Gaulle )&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual values by using:&amp;lt;pre&amp;gt;$column['index'] // e.g. $column['2']&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
# The array indices are numeric starting from zero.&lt;br /&gt;
# loadResultArray() is equivalent to loadResultArray(0).&lt;br /&gt;
&lt;br /&gt;
==== loadResultArray($index) ====&lt;br /&gt;
loadResultArray($index) returns an indexed array from a single column in the table: &lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
$query = &amp;quot;&lt;br /&gt;
  SELECT name, email, username&lt;br /&gt;
    FROM . . . &amp;quot;;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$column= $db-&amp;gt;loadResultArray(1);&lt;br /&gt;
print_r($column);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give:&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( [0] =&amp;gt; johnsmith@domain.example [1] =&amp;gt; magda_h@domain.example [2] =&amp;gt; ydg@domain.example )&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual values by using:&amp;lt;pre&amp;gt;$column['index'] // e.g. $column['2']&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
loadResultArray($index) allows you to iterate through a series of columns in the results&lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
for ( $i = 0; $i &amp;lt;= 2; $i++ ) {&lt;br /&gt;
  $column= $db-&amp;gt;loadResultArray($i);&lt;br /&gt;
  print_r($column);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give:&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( [0] =&amp;gt; John Smith [1] =&amp;gt; Magda Hellman [2] =&amp;gt; Yvonne de Gaulle )&lt;br /&gt;
Array ( [0] =&amp;gt; johnsmith@domain.example [1] =&amp;gt; magda_h@domain.example [2] =&amp;gt; ydg@domain.example )&lt;br /&gt;
Array ( [0] =&amp;gt; johnsmith [1] =&amp;gt; magdah [2] =&amp;gt; ydegaulle )&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
# The array indices are numeric starting from zero.&lt;br /&gt;
&lt;br /&gt;
=== Multi-Row Results ===&lt;br /&gt;
Each of these results functions will return multiple records from the database. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! id !! name !! email !! username&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 1 || John Smith || johnsmith@domain.example || johnsmith&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 2 || Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@domain.example || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== loadRowList() ====&lt;br /&gt;
loadRowList() returns an indexed array of indexed arrays from the table records returned by the query: &lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$row = $db-&amp;gt;loadRowList();&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( &lt;br /&gt;
[0] =&amp;gt; Array ( [0] =&amp;gt; 1 [1] =&amp;gt; John Smith [2] =&amp;gt; johnsmith@domain.example [3] =&amp;gt; johnsmith ) &lt;br /&gt;
[1] =&amp;gt; Array ( [0] =&amp;gt; 2 [1] =&amp;gt; Magda Hellman [2] =&amp;gt; magda_h@domain.example [3] =&amp;gt; magdah ) &lt;br /&gt;
[2] =&amp;gt; Array ( [0] =&amp;gt; 3 [1] =&amp;gt; Yvonne de Gaulle [2] =&amp;gt; ydg@domain.example [3] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual rows by using:&amp;lt;pre&amp;gt;$row['index'] // e.g. $row['2']&amp;lt;/pre&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;pre&amp;gt;$row['index']['index'] // e.g. $row['2']['3']&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
# The array indices are numeric starting from zero.&lt;br /&gt;
&lt;br /&gt;
==== loadAssocList() ====&lt;br /&gt;
loadAssocList() returns an indexed array of associated arrays from the table records returned by the query: &lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$row = $db-&amp;gt;loadAssocList();&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( &lt;br /&gt;
[0] =&amp;gt; Array ( [id] =&amp;gt; 1 [name] =&amp;gt; John Smith [email] =&amp;gt; johnsmith@domain.example [username] =&amp;gt; johnsmith ) &lt;br /&gt;
[1] =&amp;gt; Array ( [id] =&amp;gt; 2 [name] =&amp;gt; Magda Hellman [email] =&amp;gt; magda_h@domain.example [username] =&amp;gt; magdah ) &lt;br /&gt;
[2] =&amp;gt; Array ( [id] =&amp;gt; 3 [name] =&amp;gt; Yvonne de Gaulle [email] =&amp;gt; ydg@domain.example [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
) &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual rows by using:&amp;lt;pre&amp;gt;$row['index'] // e.g. $row['2']&amp;lt;/pre&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;pre&amp;gt;$row['index']['column_name'] // e.g. $row['2']['email']&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== loadAssocList($key) ====&lt;br /&gt;
loadAssocList('key') returns an associated array - indexed on 'key' - of associated arrays from the table records returned by the query: &lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$row = $db-&amp;gt;loadAssocList('username');&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( &lt;br /&gt;
[johnsmith] =&amp;gt; Array ( [id] =&amp;gt; 1 [name] =&amp;gt; John Smith [email] =&amp;gt; johnsmith@domain.example [username] =&amp;gt; johnsmith ) &lt;br /&gt;
[magdah] =&amp;gt; Array ( [id] =&amp;gt; 2 [name] =&amp;gt; Magda Hellman [email] =&amp;gt; magda_h@domain.example [username] =&amp;gt; magdah ) &lt;br /&gt;
[ydegaulle] =&amp;gt; Array ( [id] =&amp;gt; 3 [name] =&amp;gt; Yvonne de Gaulle [email] =&amp;gt; ydg@domain.example [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual rows by using:&amp;lt;pre&amp;gt;$row['key_value'] // e.g. $row['johnsmith']&amp;lt;/pre&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;pre&amp;gt;$row['key_value']['column_name'] // e.g. $row['johnsmith']['email']&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: Key must be a valid column name from the table; it does not have to be an Index or a Primary Key. But if it does not have a unique value you may not be able to retrieve results reliably.&lt;br /&gt;
&lt;br /&gt;
==== loadObjectList() ====&lt;br /&gt;
loadObjectList() returns an indexed array of PHP objects from the table records returned by the query: &lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$row = $db-&amp;gt;loadObjectList();&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( &lt;br /&gt;
[0] =&amp;gt; stdClass Object ( [id] =&amp;gt; 1 [name] =&amp;gt; John Smith &lt;br /&gt;
    [email] =&amp;gt; johnsmith@domain.example [username] =&amp;gt; johnsmith ) &lt;br /&gt;
[1] =&amp;gt; stdClass Object ( [id] =&amp;gt; 2 [name] =&amp;gt; Magda Hellman &lt;br /&gt;
    [email] =&amp;gt; magda_h@domain.example [username] =&amp;gt; magdah ) &lt;br /&gt;
[2] =&amp;gt; stdClass Object ( [id] =&amp;gt; 3 [name] =&amp;gt; Yvonne de Gaulle &lt;br /&gt;
    [email] =&amp;gt; ydg@domain.example [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual rows by using:&amp;lt;pre&amp;gt;$row['index'] // e.g. $row['2']&amp;lt;/pre&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;pre&amp;gt;$row['index']-&amp;gt;name // e.g. $row['2']-&amp;gt;email&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== loadObjectList('key') ====&lt;br /&gt;
loadObjectList($key) returns an associated array - indexed on 'key' - of objects from the table records returned by the query: &lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$row = $db-&amp;gt;loadObjectList('username');&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( &lt;br /&gt;
[johnsmith] =&amp;gt; stdClass Object ( [id] =&amp;gt; 1 [name] =&amp;gt; John Smith &lt;br /&gt;
    [email] =&amp;gt; johnsmith@domain.example [username] =&amp;gt; johnsmith ) &lt;br /&gt;
[magdah] =&amp;gt; stdClass Object ( [id] =&amp;gt; 2 [name] =&amp;gt; Magda Hellman &lt;br /&gt;
    [email] =&amp;gt; magda_h@domain.example [username] =&amp;gt; magdah ) &lt;br /&gt;
[ydegaulle] =&amp;gt; stdClass Object ( [id] =&amp;gt; 3 [name] =&amp;gt; Yvonne de Gaulle &lt;br /&gt;
    [email] =&amp;gt; ydg@domain.example [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual rows by using:&amp;lt;pre&amp;gt;$row['key_value'] // e.g. $row['johnsmith']&amp;lt;/pre&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;pre&amp;gt;$row['key_value']-&amp;gt;column_name // e.g. $row['johnsmith']-&amp;gt;email&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: Key must be a valid column name from the table; it does not have to be an Index or a Primary Key. But if it does not have a unique value you may not be able to retrieve results reliably.&lt;br /&gt;
&lt;br /&gt;
=== Miscellaneous Result Set Methods ===&lt;br /&gt;
==== getNumRows() ====&lt;br /&gt;
getNumRows() will return the number of result rows found by the last query and waiting to be read. To get a result from getNumRows() you have to run it '''after''' the query and '''before''' you have retrieved any results.  &lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$db-&amp;gt;query();&lt;br /&gt;
$num_rows = $db-&amp;gt;getNumRows();&lt;br /&gt;
print_r($num_rows);&lt;br /&gt;
$result = $db-&amp;gt;loadRowList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will return &amp;lt;pre&amp;gt;3&amp;lt;/pre&amp;gt;&lt;br /&gt;
Note: if you run getNumRows() after loadRowList() - or any other retrieval method - you may get a PHP Warning:&lt;br /&gt;
&amp;lt;pre&amp;gt;Warning: mysql_num_rows(): 80 is not a valid MySQL result resource &lt;br /&gt;
in D:\xampp\htdocs\joomla1.5a\libraries\joomla\database\database\mysql.php on line 344&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tips, Tricks &amp;amp; FAQ==&lt;br /&gt;
===Subqueries===&lt;br /&gt;
Subqueries should be written as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;SQL&amp;quot;&amp;gt;&lt;br /&gt;
SELECT * FROM #__example WHERE id IN (SELECT id FROM #__example2);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
These kinds of queries are supported since MySQL 4.1. If this method fails, you can split the query into two as demonstrated below. Please note that this will (often unnecessarily) increase the load on the database server.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = &amp;quot;SELECT id FROM #__example2&amp;quot;;&lt;br /&gt;
$database-&amp;gt;setQuery($query);&lt;br /&gt;
$query = &amp;quot;SELECT * FROM #__example WHERE id IN (&amp;quot;. implode(&amp;quot;,&amp;quot;, $database-&amp;gt;loadResultArray()) .&amp;quot;)&amp;quot;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Using MySQL User-Defined Variables===&lt;br /&gt;
MySQL User-Defined Variables are created and maintained for the lifespan of a connection. In Joomla terms this is usually the lifespan of a page request. They can be used in consecutive queries, retaining their value, as long as each query is inside the same connection lifespan.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$database = JFactory::getDBO();&lt;br /&gt;
$database-&amp;gt;setQuery(&amp;quot;SET @num := 0&amp;quot;);&lt;br /&gt;
$database-&amp;gt;query();&lt;br /&gt;
$database-&amp;gt;setQuery(&amp;quot;SET @num := @num + 5&amp;quot;);&lt;br /&gt;
$database-&amp;gt;query();&lt;br /&gt;
$database-&amp;gt;setQuery(&amp;quot;SELECT @num&amp;quot;);&lt;br /&gt;
$result = $localDB-&amp;gt;loadResult();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The first query defines the MySQL User-Defined Variable, the second one increments it by 5, the third one retrieves it's value and will in this case return a value of 5.&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
The fact that they retain their value can be quite useful, however there is also a little risk. If you use the same User-Defined Variable, in this case @num, in another query, make sure you reset it first. If that other query runs within the same connection lifespan, @num will have remembered its value of 5. You may expect it to start at null or 0.&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
For details on working with MySQL's User-Defined Variables, please refer to the MySQL documentation at [http://dev.mysql.com/doc/ http://dev.mysql.com/doc/]&lt;br /&gt;
&lt;br /&gt;
===Developer-Friendly Tips===&lt;br /&gt;
Here is a quick way to do four developer-friendly things at once:&lt;br /&gt;
* Use a simple constant as an SQL seperator (which can probably be used in many queries).&lt;br /&gt;
* Make your SQL-in-PHP code easy to read (for yourself and possibly other developers later on).&lt;br /&gt;
* Give an error inside your (component-) content without really setting debugging on.&lt;br /&gt;
* Have a visibly nice SQL by splitting SQL groups with linebreaks in your error.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDBO();&lt;br /&gt;
$jAp = JFactory::getApplication();&lt;br /&gt;
    //We define a linebreak constant&lt;br /&gt;
define('L', chr(10));&lt;br /&gt;
    //Here is the most magic&lt;br /&gt;
$db-&amp;gt;setQuery(&lt;br /&gt;
	'SELECT * FROM #__table'.L.&lt;br /&gt;
	'WHERE something=&amp;quot;something else&amp;quot;)'.L.&lt;br /&gt;
	'ORDER BY date desc'&lt;br /&gt;
); &lt;br /&gt;
$db-&amp;gt;query();&lt;br /&gt;
    //display and convert to HTML when SQL error&lt;br /&gt;
if (is_null($posts=$db-&amp;gt;loadRowList())) {$jAp-&amp;gt;enqueueMessage(nl2br($db-&amp;gt;getErrorMsg()),'error'); return;} &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;noinclude&amp;gt;[[Category:Tutorials]][[Category:Development]][[Category:Database]]&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===See your resulting query===&lt;br /&gt;
when building an extension, if you want to see the resulting query you can use:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
echo nl2br(str_replace('#__','jos_',$query));die; //Where 'jos_' is your database prefix &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Accessing_the_database_using_JDatabase/1.5</id>
		<title>Accessing the database using JDatabase/1.5</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Accessing_the_database_using_JDatabase/1.5"/>
				<updated>2012-10-28T02:07:24Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: Re-organizing pages into the various version implementations. This article will replace the existing Accessing the database using JDatabase article.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{version|1.5|test}}Though most of this article still works on 1.5+, some improved ways need to be specified here or in a version specific copy of this article.&amp;lt;hr/&amp;gt;&lt;br /&gt;
Joomla provides a sophisticated database abstraction layer to simplify the usage for third party developers. This guide will help you use this layer.&lt;br /&gt;
&lt;br /&gt;
==Why should I use the Joomla database class?==&lt;br /&gt;
Joomla can use different kinds of SQL database systems and run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object you need just two lines of code to get a result from the database in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.&lt;br /&gt;
&lt;br /&gt;
==Preparing the query==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Get a database object&lt;br /&gt;
$db = JFactory::getDBO();&lt;br /&gt;
&lt;br /&gt;
$query = &amp;quot;SELECT * FROM #__example_table WHERE id = 999999;&amp;quot;;&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First we instantiate the database object; then we prepare the query. You can use the normal SQL syntax. The only thing you have to change is the table prefix. To make this as flexible as possible, Joomla uses a placeholder for the prefix, the &amp;amp;ldquo;#__&amp;amp;rdquo;. In the next step, the $db-&amp;gt;setQuery(), this string is replaced with the correct prefix.&lt;br /&gt;
&lt;br /&gt;
Now, if we don't want to get information from the database, but rather insert a row into it, we need one more function. Every string value in the SQL syntax should be quoted. For example, MySQL uses backticks &amp;amp;#096;&amp;amp;#096; for names and single quotes &amp;amp;lsquo;&amp;amp;lsquo; for values. Joomla has some functions to do this for us and to ensure code compatibility between different databases. We can pass the names to the function $db-&amp;gt;nameQuote($name) and the values to the function $db-&amp;gt;Quote($value). &lt;br /&gt;
&lt;br /&gt;
A fully quoted query example is:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = &amp;quot;&lt;br /&gt;
  SELECT * &lt;br /&gt;
    FROM &amp;quot;.$db-&amp;gt;nameQuote('#__example_table').&amp;quot;  &lt;br /&gt;
    WHERE &amp;quot;.$db-&amp;gt;nameQuote('id').&amp;quot; = &amp;quot;.$db-&amp;gt;quote('999999').&amp;quot;;&lt;br /&gt;
  &amp;quot;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whatever we want to do, we have to set the query with the $db-&amp;gt;setQuery() function. Although you could write the query directly as a parameter for $db-&amp;gt;setQuery(), it's commonly done by first saving it in a variable, normally $query, and then handing this variable over. This results in clean, readable code.&lt;br /&gt;
&lt;br /&gt;
==== setQuery($query) ====&lt;br /&gt;
The ''setQuery($query)'' method sets up a database query for later execution either by the query() method or one of the Load result methods.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDBO();&lt;br /&gt;
$query = &amp;quot;/* some valid sql string */&amp;quot;;&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
The parameter $query must be a valid SQL string. It can either be added as a string parameter or as a variable. Generally a variable is preferred; it leads to more legible code and can help in debugging.&lt;br /&gt;
&lt;br /&gt;
setQuery() also takes three other parameters: $offset, $limit (both used in list pagination) and $prefix, an alternative table prefix. All three variables have default values set and can usually be ignored.&lt;br /&gt;
&lt;br /&gt;
==Executing the Query==&lt;br /&gt;
To execute the query, Joomla provides several functions, which differ in their return value.&lt;br /&gt;
&lt;br /&gt;
=== Basic Query Execution ===&lt;br /&gt;
==== query() ====&lt;br /&gt;
The ''query()'' method is the basic tool for executing SQL queries on a database. In Joomla it is most often used for updating or administering the database simply because the various load methods detailed on this page have the query step built into them.&lt;br /&gt;
&lt;br /&gt;
The syntax is very straightforward:&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;$db = JFactory::getDBO();&lt;br /&gt;
$query = &amp;quot;/* some valid sql string */&amp;quot;;&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$result = $db-&amp;gt;query();&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: $query() returns an appropriate database resource if successful, or FALSE if not.&lt;br /&gt;
&lt;br /&gt;
=== Query Execution Information ===&lt;br /&gt;
* getAffectedRows()&lt;br /&gt;
* explain()&lt;br /&gt;
&lt;br /&gt;
==== insertid() ====&lt;br /&gt;
If you insert a record into a table that contains an AUTO_INCREMENT column, you can obtain the value stored into that column by calling the insertid() function&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
$query = &amp;quot;INSERT INTO '#__example_table' ('name','email','username')&lt;br /&gt;
        VALUES ('John Smith','johnsmith@domain.example','johnsmith')&amp;quot;;&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$db-&amp;gt;query();&lt;br /&gt;
$user_id = $db-&amp;gt;insertid();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Insert Query Execution ===&lt;br /&gt;
* insertObject()&lt;br /&gt;
&lt;br /&gt;
==Query Results ==&lt;br /&gt;
The database class contains many methods for working with a query's result set.&lt;br /&gt;
&lt;br /&gt;
=== Single Value Result ===&lt;br /&gt;
==== loadResult() ====&lt;br /&gt;
Use '''loadResult()''' when you expect just a single value back from your database query. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! id !! name !! email !! username&lt;br /&gt;
|- &lt;br /&gt;
| 1 || style=&amp;quot;background:yellow&amp;quot; | John Smith || johnsmith@domain.example || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@domain.example || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This is often the result of a 'count' query to get a number of records:&lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
$db = JFactory::getDBO();&lt;br /&gt;
$query = &amp;quot;&lt;br /&gt;
  SELECT COUNT(*)&lt;br /&gt;
    FROM &amp;quot;.$db-&amp;gt;nameQuote('#__my_table').&amp;quot;&lt;br /&gt;
    WHERE &amp;quot;.$db-&amp;gt;nameQuote('name').&amp;quot; = &amp;quot;.$db-&amp;gt;quote($value).&amp;quot;;&lt;br /&gt;
  &amp;quot;;&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$count = $db-&amp;gt;loadResult();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or where you are just looking for a single field from a single row of the table (or possibly a single field from the first row returned).&lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
$db = JFactory::getDBO();&lt;br /&gt;
$query = &amp;quot;&lt;br /&gt;
  SELECT &amp;quot;.$db-&amp;gt;nameQuote('field_name').&amp;quot;&lt;br /&gt;
    FROM &amp;quot;.$db-&amp;gt;nameQuote('#__my_table').&amp;quot;&lt;br /&gt;
    WHERE &amp;quot;.$db-&amp;gt;nameQuote('some_name').&amp;quot; = &amp;quot;.$db-&amp;gt;quote($some_value).&amp;quot;;&lt;br /&gt;
  &amp;quot;;&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$result = $db-&amp;gt;loadResult();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Single Row Results ===&lt;br /&gt;
Each of these results functions will return a single record from the database even though there may be several records that meet the criteria that you have set. To get more records you need to call the function again.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! id !! name !! email !! username&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 1 || John Smith || johnsmith@domain.example || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@domain.example || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== loadRow() ====&lt;br /&gt;
loadRow() returns an indexed array from a single record in the table: &lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$row = $db-&amp;gt;loadRow();&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give:&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( [0] =&amp;gt; 1 [1] =&amp;gt; John Smith [2] =&amp;gt; johnsmith@domain.example [3] =&amp;gt; johnsmith ) &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual values by using:&amp;lt;pre&amp;gt;$row['index'] // e.g. $row['2']&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
# The array indices are numeric starting from zero.&lt;br /&gt;
# Whilst you can repeat the call to get further rows, one of the functions that returns multiple rows might be more useful.&lt;br /&gt;
&lt;br /&gt;
==== loadAssoc() ====&lt;br /&gt;
loadAssoc() returns an associated array from a single record in the table: &lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$row = $db-&amp;gt;loadAssoc();&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give:&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( [id] =&amp;gt; 1 [name] =&amp;gt; John Smith [email] =&amp;gt; johnsmith@domain.example [username] =&amp;gt; johnsmith )&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual values by using:&amp;lt;pre&amp;gt;$row['name'] // e.g. $row['name']&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
# Whilst you can repeat the call to get further rows, one of the functions that returns multiple rows might be more useful.&lt;br /&gt;
&lt;br /&gt;
==== loadObject() ====&lt;br /&gt;
loadObject returns a PHP object from a single record in the table: &lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$result = $db-&amp;gt;loadObject();&lt;br /&gt;
print_r($result);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give:&lt;br /&gt;
&amp;lt;pre&amp;gt;stdClass Object ( [id] =&amp;gt; 1 [name] =&amp;gt; John Smith [email] =&amp;gt; johnsmith@domain.example [username] =&amp;gt; johnsmith )&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual values by using:&amp;lt;pre&amp;gt;$result-&amp;gt;index // e.g. $result-&amp;gt;email&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
# Whilst you can repeat the call to get further rows, one of the functions that returns multiple rows might be more useful.&lt;br /&gt;
&lt;br /&gt;
===Single Column Results ===&lt;br /&gt;
Each of these results functions will return a single column from the database. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! id !! name !! email !! username&lt;br /&gt;
|- &lt;br /&gt;
| 1 || style=&amp;quot;background:yellow&amp;quot; | John Smith || johnsmith@domain.example || johnsmith&lt;br /&gt;
|-&lt;br /&gt;
| 2 || style=&amp;quot;background:yellow&amp;quot; | Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|-&lt;br /&gt;
| 3 || style=&amp;quot;background:yellow&amp;quot; | Yvonne de Gaulle || ydg@domain.example || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== loadResultArray() ====&lt;br /&gt;
loadResultArray() returns an indexed array from a single column in the table: &lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
$query = &amp;quot;&lt;br /&gt;
  SELECT name, email, username&lt;br /&gt;
    FROM . . . &amp;quot;;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$column= $db-&amp;gt;loadResultArray();&lt;br /&gt;
print_r($column);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give:&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( [0] =&amp;gt; John Smith [1] =&amp;gt; Magda Hellman [2] =&amp;gt; Yvonne de Gaulle )&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual values by using:&amp;lt;pre&amp;gt;$column['index'] // e.g. $column['2']&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
# The array indices are numeric starting from zero.&lt;br /&gt;
# loadResultArray() is equivalent to loadResultArray(0).&lt;br /&gt;
&lt;br /&gt;
==== loadResultArray($index) ====&lt;br /&gt;
loadResultArray($index) returns an indexed array from a single column in the table: &lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
$query = &amp;quot;&lt;br /&gt;
  SELECT name, email, username&lt;br /&gt;
    FROM . . . &amp;quot;;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$column= $db-&amp;gt;loadResultArray(1);&lt;br /&gt;
print_r($column);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give:&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( [0] =&amp;gt; johnsmith@domain.example [1] =&amp;gt; magda_h@domain.example [2] =&amp;gt; ydg@domain.example )&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual values by using:&amp;lt;pre&amp;gt;$column['index'] // e.g. $column['2']&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
loadResultArray($index) allows you to iterate through a series of columns in the results&lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
for ( $i = 0; $i &amp;lt;= 2; $i++ ) {&lt;br /&gt;
  $column= $db-&amp;gt;loadResultArray($i);&lt;br /&gt;
  print_r($column);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give:&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( [0] =&amp;gt; John Smith [1] =&amp;gt; Magda Hellman [2] =&amp;gt; Yvonne de Gaulle )&lt;br /&gt;
Array ( [0] =&amp;gt; johnsmith@domain.example [1] =&amp;gt; magda_h@domain.example [2] =&amp;gt; ydg@domain.example )&lt;br /&gt;
Array ( [0] =&amp;gt; johnsmith [1] =&amp;gt; magdah [2] =&amp;gt; ydegaulle )&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
# The array indices are numeric starting from zero.&lt;br /&gt;
&lt;br /&gt;
=== Multi-Row Results ===&lt;br /&gt;
Each of these results functions will return multiple records from the database. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! id !! name !! email !! username&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 1 || John Smith || johnsmith@domain.example || johnsmith&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 2 || Magda Hellman || magda_h@domain.example || magdah&lt;br /&gt;
|- style=&amp;quot;background:yellow&amp;quot;&lt;br /&gt;
| 3 || Yvonne de Gaulle || ydg@domain.example || ydegaulle&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== loadRowList() ====&lt;br /&gt;
loadRowList() returns an indexed array of indexed arrays from the table records returned by the query: &lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$row = $db-&amp;gt;loadRowList();&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( &lt;br /&gt;
[0] =&amp;gt; Array ( [0] =&amp;gt; 1 [1] =&amp;gt; John Smith [2] =&amp;gt; johnsmith@domain.example [3] =&amp;gt; johnsmith ) &lt;br /&gt;
[1] =&amp;gt; Array ( [0] =&amp;gt; 2 [1] =&amp;gt; Magda Hellman [2] =&amp;gt; magda_h@domain.example [3] =&amp;gt; magdah ) &lt;br /&gt;
[2] =&amp;gt; Array ( [0] =&amp;gt; 3 [1] =&amp;gt; Yvonne de Gaulle [2] =&amp;gt; ydg@domain.example [3] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual rows by using:&amp;lt;pre&amp;gt;$row['index'] // e.g. $row['2']&amp;lt;/pre&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;pre&amp;gt;$row['index']['index'] // e.g. $row['2']['3']&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
# The array indices are numeric starting from zero.&lt;br /&gt;
&lt;br /&gt;
==== loadAssocList() ====&lt;br /&gt;
loadAssocList() returns an indexed array of associated arrays from the table records returned by the query: &lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$row = $db-&amp;gt;loadAssocList();&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( &lt;br /&gt;
[0] =&amp;gt; Array ( [id] =&amp;gt; 1 [name] =&amp;gt; John Smith [email] =&amp;gt; johnsmith@domain.example [username] =&amp;gt; johnsmith ) &lt;br /&gt;
[1] =&amp;gt; Array ( [id] =&amp;gt; 2 [name] =&amp;gt; Magda Hellman [email] =&amp;gt; magda_h@domain.example [username] =&amp;gt; magdah ) &lt;br /&gt;
[2] =&amp;gt; Array ( [id] =&amp;gt; 3 [name] =&amp;gt; Yvonne de Gaulle [email] =&amp;gt; ydg@domain.example [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
) &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual rows by using:&amp;lt;pre&amp;gt;$row['index'] // e.g. $row['2']&amp;lt;/pre&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;pre&amp;gt;$row['index']['column_name'] // e.g. $row['2']['email']&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== loadAssocList($key) ====&lt;br /&gt;
loadAssocList('key') returns an associated array - indexed on 'key' - of associated arrays from the table records returned by the query: &lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$row = $db-&amp;gt;loadAssocList('username');&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( &lt;br /&gt;
[johnsmith] =&amp;gt; Array ( [id] =&amp;gt; 1 [name] =&amp;gt; John Smith [email] =&amp;gt; johnsmith@domain.example [username] =&amp;gt; johnsmith ) &lt;br /&gt;
[magdah] =&amp;gt; Array ( [id] =&amp;gt; 2 [name] =&amp;gt; Magda Hellman [email] =&amp;gt; magda_h@domain.example [username] =&amp;gt; magdah ) &lt;br /&gt;
[ydegaulle] =&amp;gt; Array ( [id] =&amp;gt; 3 [name] =&amp;gt; Yvonne de Gaulle [email] =&amp;gt; ydg@domain.example [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual rows by using:&amp;lt;pre&amp;gt;$row['key_value'] // e.g. $row['johnsmith']&amp;lt;/pre&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;pre&amp;gt;$row['key_value']['column_name'] // e.g. $row['johnsmith']['email']&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: Key must be a valid column name from the table; it does not have to be an Index or a Primary Key. But if it does not have a unique value you may not be able to retrieve results reliably.&lt;br /&gt;
&lt;br /&gt;
==== loadObjectList() ====&lt;br /&gt;
loadObjectList() returns an indexed array of PHP objects from the table records returned by the query: &lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$row = $db-&amp;gt;loadObjectList();&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( &lt;br /&gt;
[0] =&amp;gt; stdClass Object ( [id] =&amp;gt; 1 [name] =&amp;gt; John Smith &lt;br /&gt;
    [email] =&amp;gt; johnsmith@domain.example [username] =&amp;gt; johnsmith ) &lt;br /&gt;
[1] =&amp;gt; stdClass Object ( [id] =&amp;gt; 2 [name] =&amp;gt; Magda Hellman &lt;br /&gt;
    [email] =&amp;gt; magda_h@domain.example [username] =&amp;gt; magdah ) &lt;br /&gt;
[2] =&amp;gt; stdClass Object ( [id] =&amp;gt; 3 [name] =&amp;gt; Yvonne de Gaulle &lt;br /&gt;
    [email] =&amp;gt; ydg@domain.example [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual rows by using:&amp;lt;pre&amp;gt;$row['index'] // e.g. $row['2']&amp;lt;/pre&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;pre&amp;gt;$row['index']-&amp;gt;name // e.g. $row['2']-&amp;gt;email&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== loadObjectList('key') ====&lt;br /&gt;
loadObjectList($key) returns an associated array - indexed on 'key' - of objects from the table records returned by the query: &lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$row = $db-&amp;gt;loadObjectList('username');&lt;br /&gt;
print_r($row);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will give (with line breaks added for clarity):&lt;br /&gt;
&amp;lt;pre&amp;gt;Array ( &lt;br /&gt;
[johnsmith] =&amp;gt; stdClass Object ( [id] =&amp;gt; 1 [name] =&amp;gt; John Smith &lt;br /&gt;
    [email] =&amp;gt; johnsmith@domain.example [username] =&amp;gt; johnsmith ) &lt;br /&gt;
[magdah] =&amp;gt; stdClass Object ( [id] =&amp;gt; 2 [name] =&amp;gt; Magda Hellman &lt;br /&gt;
    [email] =&amp;gt; magda_h@domain.example [username] =&amp;gt; magdah ) &lt;br /&gt;
[ydegaulle] =&amp;gt; stdClass Object ( [id] =&amp;gt; 3 [name] =&amp;gt; Yvonne de Gaulle &lt;br /&gt;
    [email] =&amp;gt; ydg@domain.example [username] =&amp;gt; ydegaulle ) &lt;br /&gt;
)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can access the individual rows by using:&amp;lt;pre&amp;gt;$row['key_value'] // e.g. $row['johnsmith']&amp;lt;/pre&amp;gt;&lt;br /&gt;
and you can access the individual values by using:&amp;lt;pre&amp;gt;$row['key_value']-&amp;gt;column_name // e.g. $row['johnsmith']-&amp;gt;email&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: Key must be a valid column name from the table; it does not have to be an Index or a Primary Key. But if it does not have a unique value you may not be able to retrieve results reliably.&lt;br /&gt;
&lt;br /&gt;
=== Miscellaneous Result Set Methods ===&lt;br /&gt;
==== getNumRows() ====&lt;br /&gt;
getNumRows() will return the number of result rows found by the last query and waiting to be read. To get a result from getNumRows() you have to run it '''after''' the query and '''before''' you have retrieved any results.  &lt;br /&gt;
&amp;lt;source lang='php'&amp;gt;&lt;br /&gt;
. . .&lt;br /&gt;
$db-&amp;gt;setQuery($query);&lt;br /&gt;
$db-&amp;gt;query();&lt;br /&gt;
$num_rows = $db-&amp;gt;getNumRows();&lt;br /&gt;
print_r($num_rows);&lt;br /&gt;
$result = $db-&amp;gt;loadRowList();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will return &amp;lt;pre&amp;gt;3&amp;lt;/pre&amp;gt;&lt;br /&gt;
Note: if you run getNumRows() after loadRowList() - or any other retrieval method - you may get a PHP Warning:&lt;br /&gt;
&amp;lt;pre&amp;gt;Warning: mysql_num_rows(): 80 is not a valid MySQL result resource &lt;br /&gt;
in D:\xampp\htdocs\joomla1.5a\libraries\joomla\database\database\mysql.php on line 344&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Tips, Tricks &amp;amp; FAQ==&lt;br /&gt;
===Subqueries===&lt;br /&gt;
Subqueries should be written as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;SQL&amp;quot;&amp;gt;&lt;br /&gt;
SELECT * FROM #__example WHERE id IN (SELECT id FROM #__example2);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
These kinds of queries are supported since MySQL 4.1. If this method fails, you can split the query into two as demonstrated below. Please note that this will (often unnecessarily) increase the load on the database server.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = &amp;quot;SELECT id FROM #__example2&amp;quot;;&lt;br /&gt;
$database-&amp;gt;setQuery($query);&lt;br /&gt;
$query = &amp;quot;SELECT * FROM #__example WHERE id IN (&amp;quot;. implode(&amp;quot;,&amp;quot;, $database-&amp;gt;loadResultArray()) .&amp;quot;)&amp;quot;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Using MySQL User-Defined Variables===&lt;br /&gt;
MySQL User-Defined Variables are created and maintained for the lifespan of a connection. In Joomla terms this is usually the lifespan of a page request. They can be used in consecutive queries, retaining their value, as long as each query is inside the same connection lifespan.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$database = JFactory::getDBO();&lt;br /&gt;
$database-&amp;gt;setQuery(&amp;quot;SET @num := 0&amp;quot;);&lt;br /&gt;
$database-&amp;gt;query();&lt;br /&gt;
$database-&amp;gt;setQuery(&amp;quot;SET @num := @num + 5&amp;quot;);&lt;br /&gt;
$database-&amp;gt;query();&lt;br /&gt;
$database-&amp;gt;setQuery(&amp;quot;SELECT @num&amp;quot;);&lt;br /&gt;
$result = $localDB-&amp;gt;loadResult();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The first query defines the MySQL User-Defined Variable, the second one increments it by 5, the third one retrieves it's value and will in this case return a value of 5.&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
The fact that they retain their value can be quite useful, however there is also a little risk. If you use the same User-Defined Variable, in this case @num, in another query, make sure you reset it first. If that other query runs within the same connection lifespan, @num will have remembered its value of 5. You may expect it to start at null or 0.&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
For details on working with MySQL's User-Defined Variables, please refer to the MySQL documentation at [http://dev.mysql.com/doc/ http://dev.mysql.com/doc/]&lt;br /&gt;
&lt;br /&gt;
===Developer-Friendly Tips===&lt;br /&gt;
Here is a quick way to do four developer-friendly things at once:&lt;br /&gt;
* Use a simple constant as an SQL seperator (which can probably be used in many queries).&lt;br /&gt;
* Make your SQL-in-PHP code easy to read (for yourself and possibly other developers later on).&lt;br /&gt;
* Give an error inside your (component-) content without really setting debugging on.&lt;br /&gt;
* Have a visibly nice SQL by splitting SQL groups with linebreaks in your error.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db = JFactory::getDBO();&lt;br /&gt;
$jAp = JFactory::getApplication();&lt;br /&gt;
    //We define a linebreak constant&lt;br /&gt;
define('L', chr(10));&lt;br /&gt;
    //Here is the most magic&lt;br /&gt;
$db-&amp;gt;setQuery(&lt;br /&gt;
	'SELECT * FROM #__table'.L.&lt;br /&gt;
	'WHERE something=&amp;quot;something else&amp;quot;)'.L.&lt;br /&gt;
	'ORDER BY date desc'&lt;br /&gt;
); &lt;br /&gt;
$db-&amp;gt;query();&lt;br /&gt;
    //display and convert to HTML when SQL error&lt;br /&gt;
if (is_null($posts=$db-&amp;gt;loadRowList())) {$jAp-&amp;gt;enqueueMessage(nl2br($db-&amp;gt;getErrorMsg()),'error'); return;} &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;noinclude&amp;gt;[[Category:Tutorials]][[Category:Development]][[Category:Database]]&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===See your resulting query===&lt;br /&gt;
when building an extension, if you want to see the resulting query you can use:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
echo nl2br(str_replace('#__','jos_',$query));die; //Where 'jos_' is your database prefix &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Adding_JavaScript</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Adding_JavaScript"/>
				<updated>2012-10-28T02:04:22Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{version/tutor|1.5,2.5,3.0}}&lt;br /&gt;
&lt;br /&gt;
JavaScript (also known as ECMAScript) is a scripting language primarily used in client-side web site development to extend and enhance an end-user's experience. Joomla provides developers with easy-to-use mechanisms to include JavaScript in their extensions using existing API methods.&lt;br /&gt;
&lt;br /&gt;
There are a number of methods for including JavaScript in your Joomla extensions; some of these are described below.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
There are three methods for embedding JavaScript into your code using the Joomla API; [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script]. These methods should be called either in your component's View class (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/view.html.php) or template script (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php or in the case of a module, in its template script (&amp;lt;yourmodule&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php). &lt;br /&gt;
&lt;br /&gt;
===Inline JavaScript===&lt;br /&gt;
&lt;br /&gt;
Blocks of JavaScript code can be declared directly within a component or module's display template using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration addScriptDeclaration] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScriptDeclaration('&lt;br /&gt;
    window.event(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
        alert(&amp;quot;An inline JavaScript Declaration&amp;quot;);&lt;br /&gt;
    });&lt;br /&gt;
');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External JavaScript===&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wish to separate your JavaScript into a separate file. Separating your JavaScript into an external file can make your template code easier to read especially if the JavaScript is lengthy or complex.&lt;br /&gt;
&lt;br /&gt;
There are two ways to include a JavaScript file using the Joomla API. The first involves using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript addScript] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScript('/media/system/js/sample.js');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second uses the [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html JHTML] class' [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Add the path parameter if the path is different than 'media/system/js/'&lt;br /&gt;
JHTML::script('sample.js', 'templates/custom/js/');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The Joomla API's [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods embed JavaScript into Joomla's index.php via the jdoc head tag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;head&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] or [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods to embed JavaScript includes would result in the index.php rendering the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calling the class method [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration] would render the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot;&amp;gt;&lt;br /&gt;
window.addEvent(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
    alert(&amp;quot;Embedded block of JS here&amp;quot;);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using these methods is highly recommended as it clearly differentiates another scripting language (JavaScript) from the main PHP code, ensures all JavaScript is correctly embedded between the &amp;lt;head&amp;gt;&amp;lt;/head&amp;gt; tags and, in the case of JDocument::addScript and JHTML::script ensures that a JavaScript file is included only once (I.e. there is no .js file duplication).&lt;br /&gt;
&lt;br /&gt;
== Using a JavaScript Framework ==&lt;br /&gt;
&lt;br /&gt;
A Javascript framework provides developers with generic functionality for handling various coding tasks in a familiar, consistent and platform-independent way. A framework enables the developer to forget about the intricacies of implementing a certain function in different web browsers and focus on the requirements of the software.&lt;br /&gt;
&lt;br /&gt;
Two Javascript frameworks are provided as part of Joomla 3.0; JQuery and Mootools. JQuery is a newly introduced framework which integrates with Joomla's new Bootstrap HTML framework; Mootools is Joomla's legacy Javascript library which is now superseded by JQuery and is included for backwards compatibility with 3rd party extensions.&lt;br /&gt;
&lt;br /&gt;
In nearly all cases you should use a framework when developing Javascript in your extensions or templates and including one is very simple with Joomla's API.&lt;br /&gt;
&lt;br /&gt;
=== JQuery ===&lt;br /&gt;
&lt;br /&gt;
As of Joomla 3.0 it is highly recommended you use the JQuery framework for all your Javascript as it is loaded by nearly every template which uses the Bootstrap HTML/CSS framework. In those few instances where JQuery is not available, you can easily include the framework using the JHTMLJQuery class' framework method.&lt;br /&gt;
&lt;br /&gt;
To include the JQuery framework in your extension, you add the following code to your view.html.php or tmpl file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JHtml::_('jquery.framework');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the framework method ensures JQuery is included correctly, only once, and ensures it doesn't clash with Mootools (if also loaded).&lt;br /&gt;
&lt;br /&gt;
Then it is just a matter of leveraging the JQuery framework:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JFactory::getDocument()-&amp;gt;addScriptDeclaration('&lt;br /&gt;
(function($) {&lt;br /&gt;
    $(document).ready(function() {&lt;br /&gt;
        alert($(&amp;quot;#list li&amp;quot;).size());&lt;br /&gt;
    });&lt;br /&gt;
})(jQuery);&lt;br /&gt;
');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More information about JQuery is available at http://docs.jquery.com/How_jQuery_Works. For API documentation, visit http://docs.jquery.com/.&lt;br /&gt;
&lt;br /&gt;
=== Mootools ===&lt;br /&gt;
&lt;br /&gt;
Unless you are maintaining Javascript code which leverages Mootools or you are developing an extension for a Joomla version prior to 3.0 it is recommended you use JQuery instead.&lt;br /&gt;
&lt;br /&gt;
Firstly, you will need to include the Mootools code in your extension. To include the Mootools framework in your extension, you add the following code to your view.html.php or tmpl file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JHtml::_('behavior.framework');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code results in the same outcome as the similar JQuery framework statement; that is it ensures Mootools is included correctly and only once.&lt;br /&gt;
&lt;br /&gt;
Then using Mootools is almost identical to JQuery:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JFactory::getDocument()-&amp;gt;addScriptDeclaration('&lt;br /&gt;
window.addEvent('domready', function() {&lt;br /&gt;
    alert($(&amp;quot;list&amp;quot;).getElements(&amp;quot;li&amp;quot;).length);&lt;br /&gt;
});&lt;br /&gt;
');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More information about Mootools is available at http://mootools.net/. For API documentation, visit http://mootools.net/docs/core.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[[JHtmlBehavior::framework/11.1| JHtmlBehaviour::framework method]] from the Joomla! Framework 11.1 documentation&lt;br /&gt;
&lt;br /&gt;
[[Ajax using MooTools]]&lt;br /&gt;
&lt;br /&gt;
[[Adding Javascript moo.fx to your component]]&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
http://api.joomla.org/Joomla-Platform/HTML/JHtmlBehavior.html#methodframework&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/JavaScript&lt;br /&gt;
&lt;br /&gt;
http://www.w3schools.com/js/default.asp&lt;br /&gt;
&lt;br /&gt;
http://mootools.net/&lt;br /&gt;
&lt;br /&gt;
http://jquery.com/&lt;br /&gt;
&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Components]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Adding_JavaScript</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Adding_JavaScript"/>
				<updated>2012-10-11T08:24:18Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: /* External Links */ Link to latest api docs.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;JavaScript (also known as ECMAScript) is a scripting language primarily used in client-side web site development to extend and enhance an end-user's experience. Joomla provides developers with easy-to-use mechanisms to include JavaScript in their extensions using existing API methods.&lt;br /&gt;
&lt;br /&gt;
There are a number of methods for including JavaScript in your Joomla extensions; some of these are described below.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
There are three methods for embedding JavaScript into your code using the Joomla API; [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script]. These methods should be called either in your component's View class (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/view.html.php) or template script (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php or in the case of a module, in its template script (&amp;lt;yourmodule&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php). &lt;br /&gt;
&lt;br /&gt;
===Inline JavaScript===&lt;br /&gt;
&lt;br /&gt;
Blocks of JavaScript code can be declared directly within a component or module's display template using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration addScriptDeclaration] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScriptDeclaration('&lt;br /&gt;
    window.event(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
        alert(&amp;quot;An inline JavaScript Declaration&amp;quot;);&lt;br /&gt;
    });&lt;br /&gt;
');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External JavaScript===&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wish to separate your JavaScript into a separate file. Separating your JavaScript into an external file can make your template code easier to read especially if the JavaScript is lengthy or complex.&lt;br /&gt;
&lt;br /&gt;
There are two ways to include a JavaScript file using the Joomla API. The first involves using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript addScript] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScript('/media/system/js/sample.js');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second uses the [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html JHTML] class' [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Add the path parameter if the path is different than 'media/system/js/'&lt;br /&gt;
JHTML::script('sample.js', 'templates/custom/js/');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The Joomla API's [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods embed JavaScript into Joomla's index.php via the jdoc head tag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;head&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] or [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods to embed JavaScript includes would result in the index.php rendering the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calling the class method [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration] would render the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot;&amp;gt;&lt;br /&gt;
window.addEvent(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
    alert(&amp;quot;Embedded block of JS here&amp;quot;);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using these methods is highly recommended as it clearly differentiates another scripting language (JavaScript) from the main PHP code, ensures all JavaScript is correctly embedded between the &amp;lt;head&amp;gt;&amp;lt;/head&amp;gt; tags and, in the case of JDocument::addScript and JHTML::script ensures that a JavaScript file is included only once (I.e. there is no .js file duplication).&lt;br /&gt;
&lt;br /&gt;
== Using a JavaScript Framework ==&lt;br /&gt;
&lt;br /&gt;
A Javascript framework provides developers with generic functionality for handling various coding tasks in a familiar, consistent and platform-independent way. A framework enables the developer to forget about the intricacies of implementing a certain function in different web browsers and focus on the requirements of the software.&lt;br /&gt;
&lt;br /&gt;
Two Javascript frameworks are provided as part of Joomla 3.0; JQuery and Mootools. JQuery is a newly introduced framework which integrates with Joomla's new Bootstrap HTML framework; Mootools is Joomla's legacy Javascript library which is now superseded by JQuery and is included for backwards compatibility with 3rd party extensions.&lt;br /&gt;
&lt;br /&gt;
In nearly all cases you should use a framework when developing Javascript in your extensions or templates and including one is very simple with Joomla's API.&lt;br /&gt;
&lt;br /&gt;
=== JQuery ===&lt;br /&gt;
&lt;br /&gt;
As of Joomla 3.0 it is highly recommended you use the JQuery framework for all your Javascript as it is loaded by nearly every template which uses the Bootstrap HTML/CSS framework. In those few instances where JQuery is not available, you can easily include the framework using the JHTMLJQuery class' framework method.&lt;br /&gt;
&lt;br /&gt;
To include the JQuery framework in your extension, you add the following code to your view.html.php or tmpl file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JHtml::_('jquery.framework');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the framework method ensures JQuery is included correctly, only once, and ensures it doesn't clash with Mootools (if also loaded).&lt;br /&gt;
&lt;br /&gt;
Then it is just a matter of leveraging the JQuery framework:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JFactory::getDocument()-&amp;gt;addScriptDeclaration('&lt;br /&gt;
(function($) {&lt;br /&gt;
    $(document).ready(function() {&lt;br /&gt;
        alert($(&amp;quot;#list li&amp;quot;).size());&lt;br /&gt;
    });&lt;br /&gt;
})(jQuery);&lt;br /&gt;
');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More information about JQuery is available at http://docs.jquery.com/How_jQuery_Works. For API documentation, visit http://docs.jquery.com/.&lt;br /&gt;
&lt;br /&gt;
=== Mootools ===&lt;br /&gt;
&lt;br /&gt;
Unless you are maintaining Javascript code which leverages Mootools or you are developing an extension for a Joomla version prior to 3.0 it is recommended you use JQuery instead.&lt;br /&gt;
&lt;br /&gt;
Firstly, you will need to include the Mootools code in your extension. To include the Mootools framework in your extension, you add the following code to your view.html.php or tmpl file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JHtml::_('behavior.framework');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code results in the same outcome as the similar JQuery framework statement; that is it ensures Mootools is included correctly and only once.&lt;br /&gt;
&lt;br /&gt;
Then using Mootools is almost identical to JQuery:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JFactory::getDocument()-&amp;gt;addScriptDeclaration('&lt;br /&gt;
window.addEvent('domready', function() {&lt;br /&gt;
    alert($(&amp;quot;list&amp;quot;).getElements(&amp;quot;li&amp;quot;).length);&lt;br /&gt;
});&lt;br /&gt;
');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More information about Mootools is available at http://mootools.net/. For API documentation, visit http://mootools.net/docs/core.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[[JHtmlBehavior::framework/11.1| JHtmlBehaviour::framework method]] from the Joomla! Framework 11.1 documentation&lt;br /&gt;
&lt;br /&gt;
[[Ajax using MooTools]]&lt;br /&gt;
&lt;br /&gt;
[[Adding Javascript moo.fx to your component]]&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
http://api.joomla.org/Joomla-Platform/HTML/JHtmlBehavior.html#methodframework&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/JavaScript&lt;br /&gt;
&lt;br /&gt;
http://www.w3schools.com/js/default.asp&lt;br /&gt;
&lt;br /&gt;
http://mootools.net/&lt;br /&gt;
&lt;br /&gt;
http://jquery.com/&lt;br /&gt;
&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Components]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Adding_JavaScript</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Adding_JavaScript"/>
				<updated>2012-10-11T08:23:42Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: /* See Also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;JavaScript (also known as ECMAScript) is a scripting language primarily used in client-side web site development to extend and enhance an end-user's experience. Joomla provides developers with easy-to-use mechanisms to include JavaScript in their extensions using existing API methods.&lt;br /&gt;
&lt;br /&gt;
There are a number of methods for including JavaScript in your Joomla extensions; some of these are described below.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
There are three methods for embedding JavaScript into your code using the Joomla API; [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script]. These methods should be called either in your component's View class (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/view.html.php) or template script (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php or in the case of a module, in its template script (&amp;lt;yourmodule&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php). &lt;br /&gt;
&lt;br /&gt;
===Inline JavaScript===&lt;br /&gt;
&lt;br /&gt;
Blocks of JavaScript code can be declared directly within a component or module's display template using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration addScriptDeclaration] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScriptDeclaration('&lt;br /&gt;
    window.event(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
        alert(&amp;quot;An inline JavaScript Declaration&amp;quot;);&lt;br /&gt;
    });&lt;br /&gt;
');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External JavaScript===&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wish to separate your JavaScript into a separate file. Separating your JavaScript into an external file can make your template code easier to read especially if the JavaScript is lengthy or complex.&lt;br /&gt;
&lt;br /&gt;
There are two ways to include a JavaScript file using the Joomla API. The first involves using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript addScript] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScript('/media/system/js/sample.js');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second uses the [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html JHTML] class' [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Add the path parameter if the path is different than 'media/system/js/'&lt;br /&gt;
JHTML::script('sample.js', 'templates/custom/js/');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The Joomla API's [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods embed JavaScript into Joomla's index.php via the jdoc head tag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;head&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] or [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods to embed JavaScript includes would result in the index.php rendering the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calling the class method [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration] would render the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot;&amp;gt;&lt;br /&gt;
window.addEvent(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
    alert(&amp;quot;Embedded block of JS here&amp;quot;);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using these methods is highly recommended as it clearly differentiates another scripting language (JavaScript) from the main PHP code, ensures all JavaScript is correctly embedded between the &amp;lt;head&amp;gt;&amp;lt;/head&amp;gt; tags and, in the case of JDocument::addScript and JHTML::script ensures that a JavaScript file is included only once (I.e. there is no .js file duplication).&lt;br /&gt;
&lt;br /&gt;
== Using a JavaScript Framework ==&lt;br /&gt;
&lt;br /&gt;
A Javascript framework provides developers with generic functionality for handling various coding tasks in a familiar, consistent and platform-independent way. A framework enables the developer to forget about the intricacies of implementing a certain function in different web browsers and focus on the requirements of the software.&lt;br /&gt;
&lt;br /&gt;
Two Javascript frameworks are provided as part of Joomla 3.0; JQuery and Mootools. JQuery is a newly introduced framework which integrates with Joomla's new Bootstrap HTML framework; Mootools is Joomla's legacy Javascript library which is now superseded by JQuery and is included for backwards compatibility with 3rd party extensions.&lt;br /&gt;
&lt;br /&gt;
In nearly all cases you should use a framework when developing Javascript in your extensions or templates and including one is very simple with Joomla's API.&lt;br /&gt;
&lt;br /&gt;
=== JQuery ===&lt;br /&gt;
&lt;br /&gt;
As of Joomla 3.0 it is highly recommended you use the JQuery framework for all your Javascript as it is loaded by nearly every template which uses the Bootstrap HTML/CSS framework. In those few instances where JQuery is not available, you can easily include the framework using the JHTMLJQuery class' framework method.&lt;br /&gt;
&lt;br /&gt;
To include the JQuery framework in your extension, you add the following code to your view.html.php or tmpl file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JHtml::_('jquery.framework');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the framework method ensures JQuery is included correctly, only once, and ensures it doesn't clash with Mootools (if also loaded).&lt;br /&gt;
&lt;br /&gt;
Then it is just a matter of leveraging the JQuery framework:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JFactory::getDocument()-&amp;gt;addScriptDeclaration('&lt;br /&gt;
(function($) {&lt;br /&gt;
    $(document).ready(function() {&lt;br /&gt;
        alert($(&amp;quot;#list li&amp;quot;).size());&lt;br /&gt;
    });&lt;br /&gt;
})(jQuery);&lt;br /&gt;
');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More information about JQuery is available at http://docs.jquery.com/How_jQuery_Works. For API documentation, visit http://docs.jquery.com/.&lt;br /&gt;
&lt;br /&gt;
=== Mootools ===&lt;br /&gt;
&lt;br /&gt;
Unless you are maintaining Javascript code which leverages Mootools or you are developing an extension for a Joomla version prior to 3.0 it is recommended you use JQuery instead.&lt;br /&gt;
&lt;br /&gt;
Firstly, you will need to include the Mootools code in your extension. To include the Mootools framework in your extension, you add the following code to your view.html.php or tmpl file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JHtml::_('behavior.framework');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code results in the same outcome as the similar JQuery framework statement; that is it ensures Mootools is included correctly and only once.&lt;br /&gt;
&lt;br /&gt;
Then using Mootools is almost identical to JQuery:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JFactory::getDocument()-&amp;gt;addScriptDeclaration('&lt;br /&gt;
window.addEvent('domready', function() {&lt;br /&gt;
    alert($(&amp;quot;list&amp;quot;).getElements(&amp;quot;li&amp;quot;).length);&lt;br /&gt;
});&lt;br /&gt;
');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More information about Mootools is available at http://mootools.net/. For API documentation, visit http://mootools.net/docs/core.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[[JHtmlBehavior::framework/11.1| JHtmlBehaviour::framework method]] from the Joomla! Framework 11.1 documentation&lt;br /&gt;
&lt;br /&gt;
[[Ajax using MooTools]]&lt;br /&gt;
&lt;br /&gt;
[[Adding Javascript moo.fx to your component]]&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/JavaScript&lt;br /&gt;
&lt;br /&gt;
http://www.w3schools.com/js/default.asp&lt;br /&gt;
&lt;br /&gt;
http://mootools.net/&lt;br /&gt;
&lt;br /&gt;
http://jquery.com/&lt;br /&gt;
&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Components]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Adding_JavaScript</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Adding_JavaScript"/>
				<updated>2012-10-11T08:21:32Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: /* JQuery */ Links to getting started with JQuery.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;JavaScript (also known as ECMAScript) is a scripting language primarily used in client-side web site development to extend and enhance an end-user's experience. Joomla provides developers with easy-to-use mechanisms to include JavaScript in their extensions using existing API methods.&lt;br /&gt;
&lt;br /&gt;
There are a number of methods for including JavaScript in your Joomla extensions; some of these are described below.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
There are three methods for embedding JavaScript into your code using the Joomla API; [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script]. These methods should be called either in your component's View class (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/view.html.php) or template script (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php or in the case of a module, in its template script (&amp;lt;yourmodule&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php). &lt;br /&gt;
&lt;br /&gt;
===Inline JavaScript===&lt;br /&gt;
&lt;br /&gt;
Blocks of JavaScript code can be declared directly within a component or module's display template using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration addScriptDeclaration] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScriptDeclaration('&lt;br /&gt;
    window.event(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
        alert(&amp;quot;An inline JavaScript Declaration&amp;quot;);&lt;br /&gt;
    });&lt;br /&gt;
');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External JavaScript===&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wish to separate your JavaScript into a separate file. Separating your JavaScript into an external file can make your template code easier to read especially if the JavaScript is lengthy or complex.&lt;br /&gt;
&lt;br /&gt;
There are two ways to include a JavaScript file using the Joomla API. The first involves using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript addScript] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScript('/media/system/js/sample.js');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second uses the [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html JHTML] class' [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Add the path parameter if the path is different than 'media/system/js/'&lt;br /&gt;
JHTML::script('sample.js', 'templates/custom/js/');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The Joomla API's [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods embed JavaScript into Joomla's index.php via the jdoc head tag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;head&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] or [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods to embed JavaScript includes would result in the index.php rendering the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calling the class method [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration] would render the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot;&amp;gt;&lt;br /&gt;
window.addEvent(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
    alert(&amp;quot;Embedded block of JS here&amp;quot;);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using these methods is highly recommended as it clearly differentiates another scripting language (JavaScript) from the main PHP code, ensures all JavaScript is correctly embedded between the &amp;lt;head&amp;gt;&amp;lt;/head&amp;gt; tags and, in the case of JDocument::addScript and JHTML::script ensures that a JavaScript file is included only once (I.e. there is no .js file duplication).&lt;br /&gt;
&lt;br /&gt;
== Using a JavaScript Framework ==&lt;br /&gt;
&lt;br /&gt;
A Javascript framework provides developers with generic functionality for handling various coding tasks in a familiar, consistent and platform-independent way. A framework enables the developer to forget about the intricacies of implementing a certain function in different web browsers and focus on the requirements of the software.&lt;br /&gt;
&lt;br /&gt;
Two Javascript frameworks are provided as part of Joomla 3.0; JQuery and Mootools. JQuery is a newly introduced framework which integrates with Joomla's new Bootstrap HTML framework; Mootools is Joomla's legacy Javascript library which is now superseded by JQuery and is included for backwards compatibility with 3rd party extensions.&lt;br /&gt;
&lt;br /&gt;
In nearly all cases you should use a framework when developing Javascript in your extensions or templates and including one is very simple with Joomla's API.&lt;br /&gt;
&lt;br /&gt;
=== JQuery ===&lt;br /&gt;
&lt;br /&gt;
As of Joomla 3.0 it is highly recommended you use the JQuery framework for all your Javascript as it is loaded by nearly every template which uses the Bootstrap HTML/CSS framework. In those few instances where JQuery is not available, you can easily include the framework using the JHTMLJQuery class' framework method.&lt;br /&gt;
&lt;br /&gt;
To include the JQuery framework in your extension, you add the following code to your view.html.php or tmpl file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JHtml::_('jquery.framework');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the framework method ensures JQuery is included correctly, only once, and ensures it doesn't clash with Mootools (if also loaded).&lt;br /&gt;
&lt;br /&gt;
Then it is just a matter of leveraging the JQuery framework:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JFactory::getDocument()-&amp;gt;addScriptDeclaration('&lt;br /&gt;
(function($) {&lt;br /&gt;
    $(document).ready(function() {&lt;br /&gt;
        alert($(&amp;quot;#list li&amp;quot;).size());&lt;br /&gt;
    });&lt;br /&gt;
})(jQuery);&lt;br /&gt;
');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More information about JQuery is available at http://docs.jquery.com/How_jQuery_Works. For API documentation, visit http://docs.jquery.com/.&lt;br /&gt;
&lt;br /&gt;
=== Mootools ===&lt;br /&gt;
&lt;br /&gt;
Unless you are maintaining Javascript code which leverages Mootools or you are developing an extension for a Joomla version prior to 3.0 it is recommended you use JQuery instead.&lt;br /&gt;
&lt;br /&gt;
Firstly, you will need to include the Mootools code in your extension. To include the Mootools framework in your extension, you add the following code to your view.html.php or tmpl file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JHtml::_('behavior.framework');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code results in the same outcome as the similar JQuery framework statement; that is it ensures Mootools is included correctly and only once.&lt;br /&gt;
&lt;br /&gt;
Then using Mootools is almost identical to JQuery:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JFactory::getDocument()-&amp;gt;addScriptDeclaration('&lt;br /&gt;
window.addEvent('domready', function() {&lt;br /&gt;
    alert($(&amp;quot;list&amp;quot;).getElements(&amp;quot;li&amp;quot;).length);&lt;br /&gt;
});&lt;br /&gt;
');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More information about Mootools is available at http://mootools.net/. For API documentation, visit http://mootools.net/docs/core.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[[JHtmlBehavior::framework/11.1| JHtmlBehaviour::framework method]]&lt;br /&gt;
&lt;br /&gt;
[[Ajax using MooTools]]&lt;br /&gt;
&lt;br /&gt;
[[Adding Javascript moo.fx to your component]]&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/JavaScript&lt;br /&gt;
&lt;br /&gt;
http://www.w3schools.com/js/default.asp&lt;br /&gt;
&lt;br /&gt;
http://mootools.net/&lt;br /&gt;
&lt;br /&gt;
http://jquery.com/&lt;br /&gt;
&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Components]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Adding_JavaScript</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Adding_JavaScript"/>
				<updated>2012-10-11T08:19:08Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: /* Mootools */  Some links to mootools.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;JavaScript (also known as ECMAScript) is a scripting language primarily used in client-side web site development to extend and enhance an end-user's experience. Joomla provides developers with easy-to-use mechanisms to include JavaScript in their extensions using existing API methods.&lt;br /&gt;
&lt;br /&gt;
There are a number of methods for including JavaScript in your Joomla extensions; some of these are described below.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
There are three methods for embedding JavaScript into your code using the Joomla API; [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script]. These methods should be called either in your component's View class (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/view.html.php) or template script (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php or in the case of a module, in its template script (&amp;lt;yourmodule&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php). &lt;br /&gt;
&lt;br /&gt;
===Inline JavaScript===&lt;br /&gt;
&lt;br /&gt;
Blocks of JavaScript code can be declared directly within a component or module's display template using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration addScriptDeclaration] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScriptDeclaration('&lt;br /&gt;
    window.event(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
        alert(&amp;quot;An inline JavaScript Declaration&amp;quot;);&lt;br /&gt;
    });&lt;br /&gt;
');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External JavaScript===&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wish to separate your JavaScript into a separate file. Separating your JavaScript into an external file can make your template code easier to read especially if the JavaScript is lengthy or complex.&lt;br /&gt;
&lt;br /&gt;
There are two ways to include a JavaScript file using the Joomla API. The first involves using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript addScript] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScript('/media/system/js/sample.js');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second uses the [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html JHTML] class' [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Add the path parameter if the path is different than 'media/system/js/'&lt;br /&gt;
JHTML::script('sample.js', 'templates/custom/js/');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The Joomla API's [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods embed JavaScript into Joomla's index.php via the jdoc head tag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;head&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] or [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods to embed JavaScript includes would result in the index.php rendering the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calling the class method [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration] would render the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot;&amp;gt;&lt;br /&gt;
window.addEvent(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
    alert(&amp;quot;Embedded block of JS here&amp;quot;);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using these methods is highly recommended as it clearly differentiates another scripting language (JavaScript) from the main PHP code, ensures all JavaScript is correctly embedded between the &amp;lt;head&amp;gt;&amp;lt;/head&amp;gt; tags and, in the case of JDocument::addScript and JHTML::script ensures that a JavaScript file is included only once (I.e. there is no .js file duplication).&lt;br /&gt;
&lt;br /&gt;
== Using a JavaScript Framework ==&lt;br /&gt;
&lt;br /&gt;
A Javascript framework provides developers with generic functionality for handling various coding tasks in a familiar, consistent and platform-independent way. A framework enables the developer to forget about the intricacies of implementing a certain function in different web browsers and focus on the requirements of the software.&lt;br /&gt;
&lt;br /&gt;
Two Javascript frameworks are provided as part of Joomla 3.0; JQuery and Mootools. JQuery is a newly introduced framework which integrates with Joomla's new Bootstrap HTML framework; Mootools is Joomla's legacy Javascript library which is now superseded by JQuery and is included for backwards compatibility with 3rd party extensions.&lt;br /&gt;
&lt;br /&gt;
In nearly all cases you should use a framework when developing Javascript in your extensions or templates and including one is very simple with Joomla's API.&lt;br /&gt;
&lt;br /&gt;
=== JQuery ===&lt;br /&gt;
&lt;br /&gt;
As of Joomla 3.0 it is highly recommended you use the JQuery framework for all your Javascript as it is loaded by nearly every template which uses the Bootstrap HTML/CSS framework. In those few instances where JQuery is not available, you can easily include the framework using the JHTMLJQuery class' framework method.&lt;br /&gt;
&lt;br /&gt;
To include the JQuery framework in your extension, you add the following code to your view.html.php or tmpl file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JHtml::_('jquery.framework');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the framework method ensures JQuery is included correctly, only once, and ensures it doesn't clash with Mootools (if also loaded).&lt;br /&gt;
&lt;br /&gt;
Then it is just a matter of leveraging the JQuery framework:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JFactory::getDocument()-&amp;gt;addScriptDeclaration('&lt;br /&gt;
(function($) {&lt;br /&gt;
    $(document).ready(function() {&lt;br /&gt;
        alert($(&amp;quot;#list li&amp;quot;).size());&lt;br /&gt;
    });&lt;br /&gt;
})(jQuery);&lt;br /&gt;
');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mootools ===&lt;br /&gt;
&lt;br /&gt;
Unless you are maintaining Javascript code which leverages Mootools or you are developing an extension for a Joomla version prior to 3.0 it is recommended you use JQuery instead.&lt;br /&gt;
&lt;br /&gt;
Firstly, you will need to include the Mootools code in your extension. To include the Mootools framework in your extension, you add the following code to your view.html.php or tmpl file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JHtml::_('behavior.framework');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code results in the same outcome as the similar JQuery framework statement; that is it ensures Mootools is included correctly and only once.&lt;br /&gt;
&lt;br /&gt;
Then using Mootools is almost identical to JQuery:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JFactory::getDocument()-&amp;gt;addScriptDeclaration('&lt;br /&gt;
window.addEvent('domready', function() {&lt;br /&gt;
    alert($(&amp;quot;list&amp;quot;).getElements(&amp;quot;li&amp;quot;).length);&lt;br /&gt;
});&lt;br /&gt;
');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More information about Mootools is available at http://mootools.net/. For API documentation, visit http://mootools.net/docs/core.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[[JHtmlBehavior::framework/11.1| JHtmlBehaviour::framework method]]&lt;br /&gt;
&lt;br /&gt;
[[Ajax using MooTools]]&lt;br /&gt;
&lt;br /&gt;
[[Adding Javascript moo.fx to your component]]&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/JavaScript&lt;br /&gt;
&lt;br /&gt;
http://www.w3schools.com/js/default.asp&lt;br /&gt;
&lt;br /&gt;
http://mootools.net/&lt;br /&gt;
&lt;br /&gt;
http://jquery.com/&lt;br /&gt;
&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Components]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Adding_JavaScript</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Adding_JavaScript"/>
				<updated>2012-10-08T06:42:40Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;JavaScript (also known as ECMAScript) is a scripting language primarily used in client-side web site development to extend and enhance an end-user's experience. Joomla provides developers with easy-to-use mechanisms to include JavaScript in their extensions using existing API methods.&lt;br /&gt;
&lt;br /&gt;
There are a number of methods for including JavaScript in your Joomla extensions; some of these are described below.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
There are three methods for embedding JavaScript into your code using the Joomla API; [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script]. These methods should be called either in your component's View class (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/view.html.php) or template script (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php or in the case of a module, in its template script (&amp;lt;yourmodule&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php). &lt;br /&gt;
&lt;br /&gt;
===Inline JavaScript===&lt;br /&gt;
&lt;br /&gt;
Blocks of JavaScript code can be declared directly within a component or module's display template using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration addScriptDeclaration] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScriptDeclaration('&lt;br /&gt;
    window.event(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
        alert(&amp;quot;An inline JavaScript Declaration&amp;quot;);&lt;br /&gt;
    });&lt;br /&gt;
');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External JavaScript===&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wish to separate your JavaScript into a separate file. Separating your JavaScript into an external file can make your template code easier to read especially if the JavaScript is lengthy or complex.&lt;br /&gt;
&lt;br /&gt;
There are two ways to include a JavaScript file using the Joomla API. The first involves using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript addScript] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScript('/media/system/js/sample.js');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second uses the [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html JHTML] class' [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Add the path parameter if the path is different than 'media/system/js/'&lt;br /&gt;
JHTML::script('sample.js', 'templates/custom/js/');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The Joomla API's [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods embed JavaScript into Joomla's index.php via the jdoc head tag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;head&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] or [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods to embed JavaScript includes would result in the index.php rendering the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calling the class method [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration] would render the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot;&amp;gt;&lt;br /&gt;
window.addEvent(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
    alert(&amp;quot;Embedded block of JS here&amp;quot;);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using these methods is highly recommended as it clearly differentiates another scripting language (JavaScript) from the main PHP code, ensures all JavaScript is correctly embedded between the &amp;lt;head&amp;gt;&amp;lt;/head&amp;gt; tags and, in the case of JDocument::addScript and JHTML::script ensures that a JavaScript file is included only once (I.e. there is no .js file duplication).&lt;br /&gt;
&lt;br /&gt;
== Using a JavaScript Framework ==&lt;br /&gt;
&lt;br /&gt;
A Javascript framework provides developers with generic functionality for handling various coding tasks in a familiar, consistent and platform-independent way. A framework enables the developer to forget about the intricacies of implementing a certain function in different web browsers and focus on the requirements of the software.&lt;br /&gt;
&lt;br /&gt;
Two Javascript frameworks are provided as part of Joomla 3.0; JQuery and Mootools. JQuery is a newly introduced framework which integrates with Joomla's new Bootstrap HTML framework; Mootools is Joomla's legacy Javascript library which is now superseded by JQuery and is included for backwards compatibility with 3rd party extensions.&lt;br /&gt;
&lt;br /&gt;
In nearly all cases you should use a framework when developing Javascript in your extensions or templates and including one is very simple with Joomla's API.&lt;br /&gt;
&lt;br /&gt;
=== JQuery ===&lt;br /&gt;
&lt;br /&gt;
As of Joomla 3.0 it is highly recommended you use the JQuery framework for all your Javascript as it is loaded by nearly every template which uses the Bootstrap HTML/CSS framework. In those few instances where JQuery is not available, you can easily include the framework using the JHTMLJQuery class' framework method.&lt;br /&gt;
&lt;br /&gt;
To include the JQuery framework in your extension, you add the following code to your view.html.php or tmpl file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JHtml::_('jquery.framework');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the framework method ensures JQuery is included correctly, only once, and ensures it doesn't clash with Mootools (if also loaded).&lt;br /&gt;
&lt;br /&gt;
Then it is just a matter of leveraging the JQuery framework:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JFactory::getDocument()-&amp;gt;addScriptDeclaration('&lt;br /&gt;
(function($) {&lt;br /&gt;
    $(document).ready(function() {&lt;br /&gt;
        alert($(&amp;quot;#list li&amp;quot;).size());&lt;br /&gt;
    });&lt;br /&gt;
})(jQuery);&lt;br /&gt;
');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mootools ===&lt;br /&gt;
&lt;br /&gt;
Unless you are maintaining Javascript code which leverages Mootools or you are developing an extension for a Joomla version prior to 3.0 it is recommended you use JQuery instead.&lt;br /&gt;
&lt;br /&gt;
Firstly, you will need to include the Mootools code in your extension. To include the Mootools framework in your extension, you add the following code to your view.html.php or tmpl file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JHtml::_('behavior.framework');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code results in the same outcome as the similar JQuery framework statement; that is it ensures Mootools is included correctly and only once.&lt;br /&gt;
&lt;br /&gt;
Then using Mootools is almost identical to JQuery:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JFactory::getDocument()-&amp;gt;addScriptDeclaration('&lt;br /&gt;
window.addEvent('domready', function() {&lt;br /&gt;
    alert($(&amp;quot;list&amp;quot;).getElements(&amp;quot;li&amp;quot;).length);&lt;br /&gt;
});&lt;br /&gt;
');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information, see [[#External Links]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[[JHtmlBehavior::framework/11.1| JHtmlBehaviour::framework method]]&lt;br /&gt;
&lt;br /&gt;
[[Ajax using MooTools]]&lt;br /&gt;
&lt;br /&gt;
[[Adding Javascript moo.fx to your component]]&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/JavaScript&lt;br /&gt;
&lt;br /&gt;
http://www.w3schools.com/js/default.asp&lt;br /&gt;
&lt;br /&gt;
http://mootools.net/&lt;br /&gt;
&lt;br /&gt;
http://jquery.com/&lt;br /&gt;
&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Components]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Adding_JavaScript</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Adding_JavaScript"/>
				<updated>2012-10-08T06:21:43Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: Remove from Cookie Jar&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;JavaScript (also known as ECMAScript) is a scripting language primarily used in client-side web site development to extend and enhance an end-user's experience. Joomla provides developers with easy-to-use mechanisms to include JavaScript in their extensions using existing API methods.&lt;br /&gt;
&lt;br /&gt;
There are a number of methods for including JavaScript in your Joomla extensions; some of these are described below.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
There are three methods for embedding JavaScript into your code using the Joomla API; [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script]. These methods should be called either in your component's View class (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/view.html.php) or template script (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php or in the case of a module, in its template script (&amp;lt;yourmodule&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php). &lt;br /&gt;
&lt;br /&gt;
===Inline JavaScript===&lt;br /&gt;
&lt;br /&gt;
Blocks of JavaScript code can be declared directly within a component or module's display template using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration addScriptDeclaration] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScriptDeclaration('&lt;br /&gt;
    window.event(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
        alert(&amp;quot;An inline JavaScript Declaration&amp;quot;);&lt;br /&gt;
    });&lt;br /&gt;
');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External JavaScript===&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wish to separate your JavaScript into a separate file. Separating your JavaScript into an external file can make your template code easier to read especially if the JavaScript is lengthy or complex.&lt;br /&gt;
&lt;br /&gt;
There are two ways to include a JavaScript file using the Joomla API. The first involves using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript addScript] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScript('/media/system/js/sample.js');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second uses the [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html JHTML] class' [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Add the path parameter if the path is different than 'media/system/js/'&lt;br /&gt;
JHTML::script('sample.js', 'templates/custom/js/');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The Joomla API's [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods embed JavaScript into Joomla's index.php via the jdoc head tag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;head&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] or [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods to embed JavaScript includes would result in the index.php rendering the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calling the class method [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration] would render the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot;&amp;gt;&lt;br /&gt;
window.addEvent(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
    alert(&amp;quot;Embedded block of JS here&amp;quot;);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using these methods is highly recommended as it clearly differentiates another scripting language (JavaScript) from the main PHP code, ensures all JavaScript is correctly embedded between the &amp;lt;head&amp;gt;&amp;lt;/head&amp;gt; tags and, in the case of JDocument::addScript and JHTML::script ensures that a JavaScript file is included only once (I.e. there is no .js file duplication).&lt;br /&gt;
&lt;br /&gt;
== Using a JavaScript Framework ==&lt;br /&gt;
&lt;br /&gt;
A Javascript framework provides developers with generic functionality for handling various coding tasks in a familiar, consistent and platform-independent way. A framework enables the developer to forget about the intricacies of implementing a certain function in different web browsers and focus on the requirements of the software.&lt;br /&gt;
&lt;br /&gt;
Two Javascript frameworks are provided as part of Joomla 3.0; JQuery and Mootools. JQuery is a newly introduced framework which integrates with Joomla's new Bootstrap HTML framework; Mootools is Joomla's legacy Javascript library which is now superseded by JQuery and is included for backwards compatibility with 3rd party extensions.&lt;br /&gt;
&lt;br /&gt;
In nearly all cases you should use a framework when developing Javascript in your extensions or templates and including one is very simple with Joomla's API.&lt;br /&gt;
&lt;br /&gt;
=== JQuery ===&lt;br /&gt;
&lt;br /&gt;
As of Joomla 3.0 it is highly recommended you use the JQuery framework for all your Javascript as it is loaded by nearly every template which uses the Bootstrap HTML/CSS framework. In those few instances where JQuery is not available, you can easily include the framework using the JHTMLJQuery class' framework method.&lt;br /&gt;
&lt;br /&gt;
To include the JQuery framework in your extension, you add the following code to your view.html.php or tmpl file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JHtml::_('jquery.framework');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the framework method ensures JQuery is included correctly, only once, and ensures it doesn't clash with Mootools (if also loaded).&lt;br /&gt;
&lt;br /&gt;
Then it is just a matter of leveraging the JQuery framework:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JFactory::getDocument()-&amp;gt;addScriptDeclaration('&lt;br /&gt;
(function($) {&lt;br /&gt;
    $(document).ready(function() {&lt;br /&gt;
        alert($(&amp;quot;#list li&amp;quot;).size());&lt;br /&gt;
    });&lt;br /&gt;
})(jQuery);&lt;br /&gt;
');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mootools ===&lt;br /&gt;
&lt;br /&gt;
Unless you are maintaining Javascript code which leverages Mootools or you are developing an extension for a Joomla version prior to 3.0 it is recommended you use JQuery instead.&lt;br /&gt;
&lt;br /&gt;
Firstly, you will need to include the Mootools code in your extension. To include the Mootools framework in your extension, you add the following code to your view.html.php or tmpl file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JHtml::_('behavior.framework');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code results in the same outcome as the similar JQuery framework statement; that is it ensures Mootools is included correctly and only once.&lt;br /&gt;
&lt;br /&gt;
Then using Mootools is almost identical to JQuery:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JFactory::getDocument()-&amp;gt;addScriptDeclaration('&lt;br /&gt;
window.addEvent('domready', function() {&lt;br /&gt;
    alert($(&amp;quot;list&amp;quot;).getElements(&amp;quot;li&amp;quot;).length);&lt;br /&gt;
});&lt;br /&gt;
');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information, see [[#Further Reading]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[[JHtmlBehavior::framework/11.1| JHtmlBehaviour::framework method]]&lt;br /&gt;
&lt;br /&gt;
[[Ajax using MooTools]]&lt;br /&gt;
&lt;br /&gt;
[[Adding Javascript moo.fx to your component]]&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/JavaScript&lt;br /&gt;
&lt;br /&gt;
http://www.w3schools.com/js/default.asp&lt;br /&gt;
&lt;br /&gt;
http://mootools.net/&lt;br /&gt;
&lt;br /&gt;
http://jquery.com/&lt;br /&gt;
&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Components]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Adding_JavaScript</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Adding_JavaScript"/>
				<updated>2012-10-08T06:21:10Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{cookiejar}}&lt;br /&gt;
&lt;br /&gt;
JavaScript (also known as ECMAScript) is a scripting language primarily used in client-side web site development to extend and enhance an end-user's experience. Joomla provides developers with easy-to-use mechanisms to include JavaScript in their extensions using existing API methods.&lt;br /&gt;
&lt;br /&gt;
There are a number of methods for including JavaScript in your Joomla extensions; some of these are described below.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
There are three methods for embedding JavaScript into your code using the Joomla API; [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script]. These methods should be called either in your component's View class (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/view.html.php) or template script (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php or in the case of a module, in its template script (&amp;lt;yourmodule&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php). &lt;br /&gt;
&lt;br /&gt;
===Inline JavaScript===&lt;br /&gt;
&lt;br /&gt;
Blocks of JavaScript code can be declared directly within a component or module's display template using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration addScriptDeclaration] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScriptDeclaration('&lt;br /&gt;
    window.event(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
        alert(&amp;quot;An inline JavaScript Declaration&amp;quot;);&lt;br /&gt;
    });&lt;br /&gt;
');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External JavaScript===&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wish to separate your JavaScript into a separate file. Separating your JavaScript into an external file can make your template code easier to read especially if the JavaScript is lengthy or complex.&lt;br /&gt;
&lt;br /&gt;
There are two ways to include a JavaScript file using the Joomla API. The first involves using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript addScript] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScript('/media/system/js/sample.js');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second uses the [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html JHTML] class' [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Add the path parameter if the path is different than 'media/system/js/'&lt;br /&gt;
JHTML::script('sample.js', 'templates/custom/js/');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The Joomla API's [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods embed JavaScript into Joomla's index.php via the jdoc head tag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;head&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] or [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods to embed JavaScript includes would result in the index.php rendering the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calling the class method [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration] would render the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot;&amp;gt;&lt;br /&gt;
window.addEvent(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
    alert(&amp;quot;Embedded block of JS here&amp;quot;);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using these methods is highly recommended as it clearly differentiates another scripting language (JavaScript) from the main PHP code, ensures all JavaScript is correctly embedded between the &amp;lt;head&amp;gt;&amp;lt;/head&amp;gt; tags and, in the case of JDocument::addScript and JHTML::script ensures that a JavaScript file is included only once (I.e. there is no .js file duplication).&lt;br /&gt;
&lt;br /&gt;
== Using a JavaScript Framework ==&lt;br /&gt;
&lt;br /&gt;
A Javascript framework provides developers with generic functionality for handling various coding tasks in a familiar, consistent and platform-independent way. A framework enables the developer to forget about the intricacies of implementing a certain function in different web browsers and focus on the requirements of the software.&lt;br /&gt;
&lt;br /&gt;
Two Javascript frameworks are provided as part of Joomla 3.0; JQuery and Mootools. JQuery is a newly introduced framework which integrates with Joomla's new Bootstrap HTML framework; Mootools is Joomla's legacy Javascript library which is now superseded by JQuery and is included for backwards compatibility with 3rd party extensions.&lt;br /&gt;
&lt;br /&gt;
In nearly all cases you should use a framework when developing Javascript in your extensions or templates and including one is very simple with Joomla's API.&lt;br /&gt;
&lt;br /&gt;
=== JQuery ===&lt;br /&gt;
&lt;br /&gt;
As of Joomla 3.0 it is highly recommended you use the JQuery framework for all your Javascript as it is loaded by nearly every template which uses the Bootstrap HTML/CSS framework. In those few instances where JQuery is not available, you can easily include the framework using the JHTMLJQuery class' framework method.&lt;br /&gt;
&lt;br /&gt;
To include the JQuery framework in your extension, you add the following code to your view.html.php or tmpl file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JHtml::_('jquery.framework');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the framework method ensures JQuery is included correctly, only once, and ensures it doesn't clash with Mootools (if also loaded).&lt;br /&gt;
&lt;br /&gt;
Then it is just a matter of leveraging the JQuery framework:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JFactory::getDocument()-&amp;gt;addScriptDeclaration('&lt;br /&gt;
(function($) {&lt;br /&gt;
    $(document).ready(function() {&lt;br /&gt;
        alert($(&amp;quot;#list li&amp;quot;).size());&lt;br /&gt;
    });&lt;br /&gt;
})(jQuery);&lt;br /&gt;
');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mootools ===&lt;br /&gt;
&lt;br /&gt;
Unless you are maintaining Javascript code which leverages Mootools or you are developing an extension for a Joomla version prior to 3.0 it is recommended you use JQuery instead.&lt;br /&gt;
&lt;br /&gt;
Firstly, you will need to include the Mootools code in your extension. To include the Mootools framework in your extension, you add the following code to your view.html.php or tmpl file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JHtml::_('behavior.framework');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code results in the same outcome as the similar JQuery framework statement; that is it ensures Mootools is included correctly and only once.&lt;br /&gt;
&lt;br /&gt;
Then using Mootools is almost identical to JQuery:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JFactory::getDocument()-&amp;gt;addScriptDeclaration('&lt;br /&gt;
window.addEvent('domready', function() {&lt;br /&gt;
    alert($(&amp;quot;list&amp;quot;).getElements(&amp;quot;li&amp;quot;).length);&lt;br /&gt;
});&lt;br /&gt;
');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information, see [[#Further Reading]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
[[JHtmlBehavior::framework/11.1| JHtmlBehaviour::framework method]]&lt;br /&gt;
&lt;br /&gt;
[[Ajax using MooTools]]&lt;br /&gt;
&lt;br /&gt;
[[Adding Javascript moo.fx to your component]]&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
&lt;br /&gt;
http://en.wikipedia.org/wiki/JavaScript&lt;br /&gt;
&lt;br /&gt;
http://www.w3schools.com/js/default.asp&lt;br /&gt;
&lt;br /&gt;
http://mootools.net/&lt;br /&gt;
&lt;br /&gt;
http://jquery.com/&lt;br /&gt;
&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Components]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Adding_JavaScript</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Adding_JavaScript"/>
				<updated>2012-10-08T06:06:28Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: Introduction to javascript frameworks.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{cookiejar}}&lt;br /&gt;
&lt;br /&gt;
JavaScript (also known as ECMAScript) is a scripting language primarily used in client-side web site development to extend and enhance an end-user's experience. Joomla provides developers with easy-to-use mechanisms to include JavaScript in their extensions using existing API methods.&lt;br /&gt;
&lt;br /&gt;
There are a number of methods for including JavaScript in your Joomla extensions; some of these are described below.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
There are three methods for embedding JavaScript into your code using the Joomla API; [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script]. These methods should be called either in your component's View class (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/view.html.php) or template script (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php or in the case of a module, in its template script (&amp;lt;yourmodule&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php). &lt;br /&gt;
&lt;br /&gt;
===Inline JavaScript===&lt;br /&gt;
&lt;br /&gt;
Blocks of JavaScript code can be declared directly within a component or module's display template using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration addScriptDeclaration] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScriptDeclaration('&lt;br /&gt;
    window.event(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
        alert(&amp;quot;An inline JavaScript Declaration&amp;quot;);&lt;br /&gt;
    });&lt;br /&gt;
');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External JavaScript===&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wish to separate your JavaScript into a separate file. Separating your JavaScript into an external file can make your template code easier to read especially if the JavaScript is lengthy or complex.&lt;br /&gt;
&lt;br /&gt;
There are two ways to include a JavaScript file using the Joomla API. The first involves using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript addScript] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScript('/media/system/js/sample.js');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second uses the [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html JHTML] class' [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Add the path parameter if the path is different than 'media/system/js/'&lt;br /&gt;
JHTML::script('sample.js', 'templates/custom/js/');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The Joomla API's [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods embed JavaScript into Joomla's index.php via the jdoc head tag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;head&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] or [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods to embed JavaScript includes would result in the index.php rendering the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calling the class method [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration] would render the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot;&amp;gt;&lt;br /&gt;
window.addEvent(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
    alert(&amp;quot;Embedded block of JS here&amp;quot;);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using these methods is highly recommended as it clearly differentiates another scripting language (JavaScript) from the main PHP code, ensures all JavaScript is correctly embedded between the &amp;lt;head&amp;gt;&amp;lt;/head&amp;gt; tags and, in the case of JDocument::addScript and JHTML::script ensures that a JavaScript file is included only once (I.e. there is no .js file duplication).&lt;br /&gt;
&lt;br /&gt;
== Using a JavaScript Framework ==&lt;br /&gt;
&lt;br /&gt;
A Javascript framework provides developers with generic functionality for handling various coding tasks in a familiar, consistent and platform-independent way. A framework enables the developer to forget about the intricacies of implementing a certain function in different web browsers and focus on the requirements of the software.&lt;br /&gt;
&lt;br /&gt;
Two Javascript frameworks are provided as part of Joomla 3.0; JQuery and Mootools. JQuery is a newly introduced framework which integrates with Joomla's new Bootstrap HTML framework; Mootools is Joomla's legacy Javascript library which is now superseded by JQuery and is included for backwards compatibility with 3rd party extensions.&lt;br /&gt;
&lt;br /&gt;
In nearly all cases you should use a framework when developing Javascript in your extensions or templates and including one is very simple with Joomla's API.&lt;br /&gt;
&lt;br /&gt;
=== JQuery ===&lt;br /&gt;
&lt;br /&gt;
As of Joomla 3.0 it is highly recommended you use the JQuery framework for all your Javascript as it is loaded by nearly every template which uses the Bootstrap HTML/CSS framework. In those few instances where JQuery is not available, you can easily include the framework using the JHTMLJQuery class' framework method.&lt;br /&gt;
&lt;br /&gt;
To include the JQuery framework in your extension, you add the following code to your view.html.php or tmpl file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JHtml::_('jquery.framework');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the framework method ensures JQuery is included correctly, only once, and ensures it doesn't clash with Mootools (if also loaded).&lt;br /&gt;
&lt;br /&gt;
Then it is just a matter of leveraging the JQuery framework:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JFactory::getDocument()-&amp;gt;addScriptDeclaration('&lt;br /&gt;
(function($) {&lt;br /&gt;
    $(document).ready(function() {&lt;br /&gt;
        alert($(&amp;quot;#list li&amp;quot;).size());&lt;br /&gt;
    });&lt;br /&gt;
})(jQuery);&lt;br /&gt;
');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mootools ===&lt;br /&gt;
&lt;br /&gt;
Unless you are maintaining Javascript code which leverages Mootools or you are developing an extension for a Joomla version prior to 3.0 it is recommended you use JQuery instead.&lt;br /&gt;
&lt;br /&gt;
Firstly, you will need to include the Mootools code in your extension. To include the Mootools framework in your extension, you add the following code to your view.html.php or tmpl file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JHtml::_('behavior.framework');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code results in the same outcome as the similar JQuery framework statement; that is it ensures Mootools is included correctly and only once.&lt;br /&gt;
&lt;br /&gt;
Then using Mootools is almost identical to JQuery:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JFactory::getDocument()-&amp;gt;addScriptDeclaration('&lt;br /&gt;
window.addEvent('domready', function() {&lt;br /&gt;
    alert($(&amp;quot;list&amp;quot;).getElements(&amp;quot;li&amp;quot;).length);&lt;br /&gt;
});&lt;br /&gt;
');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information, see [[#Further Reading]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Components]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Adding_JavaScript</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Adding_JavaScript"/>
				<updated>2012-09-17T23:02:46Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: See also heading&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{cookiejar}}&lt;br /&gt;
&lt;br /&gt;
JavaScript (also known as ECMAScript) is a scripting language primarily used in client-side web site development to extend and enhance an end-user's experience. Joomla provides developers with easy-to-use mechanisms to include JavaScript in their extensions using existing API methods.&lt;br /&gt;
&lt;br /&gt;
There are a number of methods for including JavaScript in your Joomla extensions; some of these are described below.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
There are three methods for embedding JavaScript into your code using the Joomla API; [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script]. These methods should be called either in your component's View class (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/view.html.php) or template script (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php or in the case of a module, in its template script (&amp;lt;yourmodule&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php). &lt;br /&gt;
&lt;br /&gt;
===Inline JavaScript===&lt;br /&gt;
&lt;br /&gt;
Blocks of JavaScript code can be declared directly within a component or module's display template using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration addScriptDeclaration] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScriptDeclaration('&lt;br /&gt;
    window.event(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
        alert(&amp;quot;An inline JavaScript Declaration&amp;quot;);&lt;br /&gt;
    });&lt;br /&gt;
');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External JavaScript===&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wish to separate your JavaScript into a separate file. Separating your JavaScript into an external file can make your template code easier to read especially if the JavaScript is lengthy or complex.&lt;br /&gt;
&lt;br /&gt;
There are two ways to include a JavaScript file using the Joomla API. The first involves using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript addScript] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScript('/media/system/js/sample.js');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second uses the [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html JHTML] class' [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Add the path parameter if the path is different than 'media/system/js/'&lt;br /&gt;
JHTML::script('sample.js', 'templates/custom/js/');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The Joomla API's [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods embed JavaScript into Joomla's index.php via the jdoc head tag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;head&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] or [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods to embed JavaScript includes would result in the index.php rendering the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calling the class method [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration] would render the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot;&amp;gt;&lt;br /&gt;
window.addEvent(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
    alert(&amp;quot;Embedded block of JS here&amp;quot;);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using these methods is highly recommended as it clearly differentiates another scripting language (JavaScript) from the main PHP code, ensures all JavaScript is correctly embedded between the &amp;lt;head&amp;gt;&amp;lt;/head&amp;gt; tags and, in the case of JDocument::addScript and JHTML::script ensures that a JavaScript file is included only once (I.e. there is no .js file duplication).&lt;br /&gt;
&lt;br /&gt;
== Using JavaScript Libraries ==&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Components]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Adding_JavaScript</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Adding_JavaScript"/>
				<updated>2012-09-17T23:01:28Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: Further reading heading.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{cookiejar}}&lt;br /&gt;
&lt;br /&gt;
JavaScript (also known as ECMAScript) is a scripting language primarily used in client-side web site development to extend and enhance an end-user's experience. Joomla provides developers with easy-to-use mechanisms to include JavaScript in their extensions using existing API methods.&lt;br /&gt;
&lt;br /&gt;
There are a number of methods for including JavaScript in your Joomla extensions; some of these are described below.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
There are three methods for embedding JavaScript into your code using the Joomla API; [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script]. These methods should be called either in your component's View class (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/view.html.php) or template script (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php or in the case of a module, in its template script (&amp;lt;yourmodule&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php). &lt;br /&gt;
&lt;br /&gt;
===Inline JavaScript===&lt;br /&gt;
&lt;br /&gt;
Blocks of JavaScript code can be declared directly within a component or module's display template using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration addScriptDeclaration] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScriptDeclaration('&lt;br /&gt;
    window.event(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
        alert(&amp;quot;An inline JavaScript Declaration&amp;quot;);&lt;br /&gt;
    });&lt;br /&gt;
');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External JavaScript===&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wish to separate your JavaScript into a separate file. Separating your JavaScript into an external file can make your template code easier to read especially if the JavaScript is lengthy or complex.&lt;br /&gt;
&lt;br /&gt;
There are two ways to include a JavaScript file using the Joomla API. The first involves using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript addScript] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScript('/media/system/js/sample.js');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second uses the [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html JHTML] class' [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Add the path parameter if the path is different than 'media/system/js/'&lt;br /&gt;
JHTML::script('sample.js', 'templates/custom/js/');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The Joomla API's [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods embed JavaScript into Joomla's index.php via the jdoc head tag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;head&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] or [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods to embed JavaScript includes would result in the index.php rendering the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calling the class method [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration] would render the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot;&amp;gt;&lt;br /&gt;
window.addEvent(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
    alert(&amp;quot;Embedded block of JS here&amp;quot;);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using these methods is highly recommended as it clearly differentiates another scripting language (JavaScript) from the main PHP code, ensures all JavaScript is correctly embedded between the &amp;lt;head&amp;gt;&amp;lt;/head&amp;gt; tags and, in the case of JDocument::addScript and JHTML::script ensures that a JavaScript file is included only once (I.e. there is no .js file duplication).&lt;br /&gt;
&lt;br /&gt;
== Using JavaScript Libraries ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Components]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Adding_JavaScript</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Adding_JavaScript"/>
				<updated>2012-09-17T23:01:01Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: New heading for covering Mootools. Keeping the heading generic for upcoming JQuery update.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{cookiejar}}&lt;br /&gt;
&lt;br /&gt;
JavaScript (also known as ECMAScript) is a scripting language primarily used in client-side web site development to extend and enhance an end-user's experience. Joomla provides developers with easy-to-use mechanisms to include JavaScript in their extensions using existing API methods.&lt;br /&gt;
&lt;br /&gt;
There are a number of methods for including JavaScript in your Joomla extensions; some of these are described below.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
There are three methods for embedding JavaScript into your code using the Joomla API; [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script]. These methods should be called either in your component's View class (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/view.html.php) or template script (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php or in the case of a module, in its template script (&amp;lt;yourmodule&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php). &lt;br /&gt;
&lt;br /&gt;
===Inline JavaScript===&lt;br /&gt;
&lt;br /&gt;
Blocks of JavaScript code can be declared directly within a component or module's display template using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration addScriptDeclaration] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScriptDeclaration('&lt;br /&gt;
    window.event(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
        alert(&amp;quot;An inline JavaScript Declaration&amp;quot;);&lt;br /&gt;
    });&lt;br /&gt;
');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External JavaScript===&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wish to separate your JavaScript into a separate file. Separating your JavaScript into an external file can make your template code easier to read especially if the JavaScript is lengthy or complex.&lt;br /&gt;
&lt;br /&gt;
There are two ways to include a JavaScript file using the Joomla API. The first involves using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript addScript] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScript('/media/system/js/sample.js');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second uses the [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html JHTML] class' [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Add the path parameter if the path is different than 'media/system/js/'&lt;br /&gt;
JHTML::script('sample.js', 'templates/custom/js/');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The Joomla API's [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods embed JavaScript into Joomla's index.php via the jdoc head tag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;head&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] or [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods to embed JavaScript includes would result in the index.php rendering the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calling the class method [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration] would render the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot;&amp;gt;&lt;br /&gt;
window.addEvent(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
    alert(&amp;quot;Embedded block of JS here&amp;quot;);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using these methods is highly recommended as it clearly differentiates another scripting language (JavaScript) from the main PHP code, ensures all JavaScript is correctly embedded between the &amp;lt;head&amp;gt;&amp;lt;/head&amp;gt; tags and, in the case of JDocument::addScript and JHTML::script ensures that a JavaScript file is included only once (I.e. there is no .js file duplication).&lt;br /&gt;
&lt;br /&gt;
== Using JavaScript Libraries ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Components]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Adding_JavaScript</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Adding_JavaScript"/>
				<updated>2012-09-17T22:59:39Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{cookiejar}}&lt;br /&gt;
&lt;br /&gt;
JavaScript (also known as ECMAScript) is a scripting language primarily used in client-side web site development to extend and enhance an end-user's experience. Joomla provides developers with easy-to-use mechanisms to include JavaScript in their extensions using existing API methods.&lt;br /&gt;
&lt;br /&gt;
There are a number of methods for including JavaScript in your Joomla extensions; some of these are described below.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
There are three methods for embedding JavaScript into your code using the Joomla API; [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script]. These methods should be called either in your component's View class (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/view.html.php) or template script (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php or in the case of a module, in its template script (&amp;lt;yourmodule&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php). &lt;br /&gt;
&lt;br /&gt;
===Inline JavaScript===&lt;br /&gt;
&lt;br /&gt;
Blocks of JavaScript code can be declared directly within a component or module's display template using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration addScriptDeclaration] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScriptDeclaration('&lt;br /&gt;
    window.event(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
        alert(&amp;quot;An inline JavaScript Declaration&amp;quot;);&lt;br /&gt;
    });&lt;br /&gt;
');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External JavaScript===&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wish to separate your JavaScript into a separate file. Separating your JavaScript into an external file can make your template code easier to read especially if the JavaScript is lengthy or complex.&lt;br /&gt;
&lt;br /&gt;
There are two ways to include a JavaScript file using the Joomla API. The first involves using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript addScript] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScript('/media/system/js/sample.js');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second uses the [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html JHTML] class' [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Add the path parameter if the path is different than 'media/system/js/'&lt;br /&gt;
JHTML::script('sample.js', 'templates/custom/js/');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The Joomla API's [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods embed JavaScript into Joomla's index.php via the jdoc head tag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;head&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] or [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods to embed JavaScript includes would result in the index.php rendering the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calling the class method [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration] would render the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot;&amp;gt;&lt;br /&gt;
window.addEvent(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
    alert(&amp;quot;Embedded block of JS here&amp;quot;);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using these methods is highly recommended as it clearly differentiates another scripting language (JavaScript) from the main PHP code, ensures all JavaScript is correctly embedded between the &amp;lt;head&amp;gt;&amp;lt;/head&amp;gt; tags and, in the case of JDocument::addScript and JHTML::script ensures that a JavaScript file is included only once (I.e. there is no .js file duplication).&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Components]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Adding_JavaScript</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Adding_JavaScript"/>
				<updated>2012-09-17T22:55:27Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: Keep spelling of JavaScript same throughout document.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{cookiejar}}&lt;br /&gt;
&lt;br /&gt;
JavaScript (also known as ECMAScript) is a scripting language primarily used in client-side web site development to extend and enhance an end-user's experience. Joomla provides developers with easy-to-use mechanisms to include JavaScript in their extensions using existing API methods.&lt;br /&gt;
&lt;br /&gt;
There are a number of methods for including JavaScript in your Joomla extensions; some of these are described below.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
There are three methods for embedding JavaScript into your code using the Joomla API; [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script]. These methods should be called either in your component's View class (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/view.html.php) or template script (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php or in the case of a module, in its template script (&amp;lt;yourmodule&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php). &lt;br /&gt;
&lt;br /&gt;
===Inline JavaScript===&lt;br /&gt;
&lt;br /&gt;
Blocks of JavaScript code can be declared directly within a component or module's display template using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration addScriptDeclaration] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScriptDeclaration('&lt;br /&gt;
    window.event(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
        alert(&amp;quot;An inline JavaScript Declaration&amp;quot;);&lt;br /&gt;
    });&lt;br /&gt;
');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External JavaScript===&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wish to separate your JavaScript into a separate file. Separating your JavaScript into an external file can make your template code easier to read especially if the JavaScript is lengthy or complex.&lt;br /&gt;
&lt;br /&gt;
There are two ways to include a JavaScript file using the Joomla API. The first involves using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript addScript] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScript('/media/system/js/sample.js');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second uses the [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html JHTML] class' [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Add the path parameter if the path is different than 'media/system/js/'&lt;br /&gt;
JHTML::script('sample.js', 'templates/custom/js/');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The Joomla API's [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods embed JavaScript into Joomla's index.php via the jdoc head tag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;head&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] or [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods to embed JavaScript includes would result in the index.php rendering the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calling the class method [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration] would render the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javaScript&amp;quot;&amp;gt;&lt;br /&gt;
window.addEvent(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
    alert(&amp;quot;Embedded block of JS here&amp;quot;);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using these methods is highly recommended as it clearly differentiates another scripting language (JavaScript) from the main PHP code, ensures all JavaScript is correctly embedded between the &amp;lt;head&amp;gt;&amp;lt;/head&amp;gt; tags and, in the case of JDocument::addScript and JHTML::script ensures that a JavaScript file is included only once (I.e. there is no .js file duplication).&lt;br /&gt;
&lt;br /&gt;
'''Please Note:''' Joomla 1.6+ may handle MooTools differently than in previous versions. &amp;lt;ref&amp;gt;[http://forum.joomla.org/viewtopic.php?f=502&amp;amp;t=273960 Whitepaper] Upgrade to mootools 1.2&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Components]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Adding_JavaScript</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Adding_JavaScript"/>
				<updated>2012-09-17T22:53:43Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: Usage introduction.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{cookiejar}}&lt;br /&gt;
&lt;br /&gt;
Javascript (also known as ECMAScript) is a scripting language primarily used in client-side web site development to extend and enhance an end-user's experience. Joomla provides developers with easy-to-use mechanisms to include Javascript in their extensions using existing API methods.&lt;br /&gt;
&lt;br /&gt;
There are a number of methods for including Javascript in your Joomla extensions; some of these are described below.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
There are three methods for embedding JavaScript into your code using the Joomla API; [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script]. These methods should be called either in your component's View class (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/view.html.php) or template script (&amp;lt;yourcomponent&amp;gt;/views/&amp;lt;yourview&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php or in the case of a module, in its template script (&amp;lt;yourmodule&amp;gt;/tmpl/&amp;lt;yourtemplate&amp;gt;.php). &lt;br /&gt;
&lt;br /&gt;
===Inline Javascript===&lt;br /&gt;
&lt;br /&gt;
Blocks of Javascript code can be declared directly within a component or module's display template using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration addScriptDeclaration] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScriptDeclaration('&lt;br /&gt;
    window.event(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
        alert(&amp;quot;An inline Javascript Declaration&amp;quot;);&lt;br /&gt;
    });&lt;br /&gt;
');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External Javascript===&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wish to separate your Javascript into a separate file. Separating your Javascript into an external file can make your template code easier to read especially if the Javascript is lengthy or complex.&lt;br /&gt;
&lt;br /&gt;
There are two ways to include a Javascript file using the Joomla API. The first involves using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript addScript] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScript('/media/system/js/sample.js');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second uses the [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html JHTML] class' [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Add the path parameter if the path is different than 'media/system/js/'&lt;br /&gt;
JHTML::script('sample.js', 'templates/custom/js/');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The Joomla API's [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods embed Javascript into Joomla's index.php via the jdoc head tag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;head&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] or [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods to embed Javascript includes would result in the index.php rendering the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calling the class method [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration] would render the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
window.addEvent(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
    alert(&amp;quot;Embedded block of JS here&amp;quot;);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using these methods is highly recommended as it clearly differentiates another scripting language (Javascript) from the main PHP code, ensures all Javascript is correctly embedded between the &amp;lt;head&amp;gt;&amp;lt;/head&amp;gt; tags and, in the case of JDocument::addScript and JHTML::script ensures that a Javascript file is included only once (I.e. there is no .js file duplication).&lt;br /&gt;
&lt;br /&gt;
'''Please Note:''' Joomla 1.6+ may handle MooTools differently than in previous versions. &amp;lt;ref&amp;gt;[http://forum.joomla.org/viewtopic.php?f=502&amp;amp;t=273960 Whitepaper] Upgrade to mootools 1.2&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Components]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Adding_JavaScript</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Adding_JavaScript"/>
				<updated>2012-09-17T13:19:42Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{cookiejar}}&lt;br /&gt;
&lt;br /&gt;
Javascript (also known as ECMAScript) is a scripting language primarily used in client-side web site development to extend and enhance an end-user's experience. Joomla provides developers with easy-to-use mechanisms to include Javascript in their extensions using existing API methods.&lt;br /&gt;
&lt;br /&gt;
There are a number of methods for including Javascript in your Joomla extensions; some of these are described below.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
===Inline Javascript===&lt;br /&gt;
&lt;br /&gt;
Blocks of Javascript code can be declared directly within a component or module's display template using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration addScriptDeclaration] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScriptDeclaration('&lt;br /&gt;
    window.event(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
        alert(&amp;quot;An inline Javascript Declaration&amp;quot;);&lt;br /&gt;
    });&lt;br /&gt;
');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External Javascript===&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wish to separate your Javascript into a separate file. Separating your Javascript into an external file can make your template code easier to read especially if the Javascript is lengthy or complex.&lt;br /&gt;
&lt;br /&gt;
There are two ways to include a Javascript file using the Joomla API. The first involves using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript addScript] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScript('/media/system/js/sample.js');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second uses the [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html JHTML] class' [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Add the path parameter if the path is different than 'media/system/js/'&lt;br /&gt;
JHTML::script('sample.js', 'templates/custom/js/');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The Joomla API's [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods embed Javascript into Joomla's index.php via the jdoc head tag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;head&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] or [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods to embed Javascript includes would result in the index.php rendering the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calling the class method [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration] would render the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
window.addEvent(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
    alert(&amp;quot;Embedded block of JS here&amp;quot;);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using these methods is highly recommended as it clearly differentiates another scripting language (Javascript) from the main PHP code, ensures all Javascript is correctly embedded between the &amp;lt;head&amp;gt;&amp;lt;/head&amp;gt; tags and, in the case of JDocument::addScript and JHTML::script ensures that a Javascript file is included only once (I.e. there is no .js file duplication).&lt;br /&gt;
&lt;br /&gt;
'''Please Note:''' Joomla 1.6+ may handle MooTools differently than in previous versions. &amp;lt;ref&amp;gt;[http://forum.joomla.org/viewtopic.php?f=502&amp;amp;t=273960 Whitepaper] Upgrade to mootools 1.2&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Components]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Adding_JavaScript</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Adding_JavaScript"/>
				<updated>2012-09-17T13:10:01Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{cookiejar}}&lt;br /&gt;
&lt;br /&gt;
Javascript (also known as ECMAScript) is a scripting language and is primarily used in client-side web site development to extend and enhance an end-user's experience. Joomla provides developers with easy-to-use mechanisms to include Javascript in their extensions using existing API methods.&lt;br /&gt;
&lt;br /&gt;
There are a number of methods for including Javascript in your Joomla extensions; some of these are described below.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
===Inline Javascript===&lt;br /&gt;
&lt;br /&gt;
Blocks of Javascript code can be declared directly within a component or module's display template using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration addScriptDeclaration] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScriptDeclaration('&lt;br /&gt;
    window.event(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
        alert(&amp;quot;An inline Javascript Declaration&amp;quot;);&lt;br /&gt;
    });&lt;br /&gt;
');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External Javascript===&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wish to separate your Javascript into a separate file. Separating your Javascript into an external file can make your template code easier to read especially if the Javascript is lengthy or complex.&lt;br /&gt;
&lt;br /&gt;
There are two ways to include a Javascript file using the Joomla API. The first involves using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript addScript] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScript('/media/system/js/sample.js');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second uses the [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html JHTML] class' [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Add the path parameter if the path is different than 'media/system/js/'&lt;br /&gt;
JHTML::script('sample.js', 'templates/custom/js/');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The Joomla API's [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods embed Javascript into Joomla's index.php via the jdoc head tag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;head&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] or [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods to embed Javascript includes would result in the index.php rendering the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calling the class method [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration] would render the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
window.addEvent(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
    alert(&amp;quot;Embedded block of JS here&amp;quot;);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using these methods is highly recommended as it clearly differentiates another scripting language (Javascript) from the main PHP code, ensures all Javascript is correctly embedded between the &amp;lt;head&amp;gt;&amp;lt;/head&amp;gt; tags and, in the case of JDocument::addScript and JHTML::script ensures that a Javascript file is included only once (I.e. there is no .js file duplication).&lt;br /&gt;
&lt;br /&gt;
'''Please Note:''' Joomla 1.6+ may handle MooTools differently than in previous versions. &amp;lt;ref&amp;gt;[http://forum.joomla.org/viewtopic.php?f=502&amp;amp;t=273960 Whitepaper] Upgrade to mootools 1.2&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Components]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Adding_JavaScript</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Adding_JavaScript"/>
				<updated>2012-09-17T13:09:11Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
{{cookiejar}}&lt;br /&gt;
&lt;br /&gt;
Javascript (also known as ECMAScript) is a scripting language and is primarily used in client-side web site development to extend and enhance an end-user's experience. Joomla provides developers with easy-to-use mechanisms to include Javascript in their extensions using existing API methods.&lt;br /&gt;
&lt;br /&gt;
There are a number of methods for including Javascript in your Joomla extensions; some of these are described below.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
===Inline Javascript===&lt;br /&gt;
&lt;br /&gt;
Blocks of Javascript code can be declared directly within a component or module's display template using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration addScriptDeclaration] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScriptDeclaration('&lt;br /&gt;
    window.event(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
        alert(&amp;quot;An inline Javascript Declaration&amp;quot;);&lt;br /&gt;
    });&lt;br /&gt;
');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External Javascript===&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wish to separate your Javascript into a separate file. Separating your Javascript into an external file can make your template code easier to read especially if the Javascript is lengthy or complex.&lt;br /&gt;
&lt;br /&gt;
There are two ways to include a Javascript file using the Joomla API. The first involves using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript addScript] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScript('/media/system/js/sample.js');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second uses the [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html JHTML] class' [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Add the path parameter if the path is different than 'media/system/js/'&lt;br /&gt;
JHTML::script('sample.js', 'templates/custom/js/');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The Joomla API's [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods embed Javascript into Joomla's index.php via the jdoc head tag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;head&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] or [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods to embed Javascript includes would result in the index.php rendering the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calling the class method [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration] would render the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
window.addEvent(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
    alert(&amp;quot;Embedded block of JS here&amp;quot;);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using these methods is highly recommended as it clearly differentiates another scripting language (Javascript) from the main PHP code, ensures all Javascript is correctly embedded between the &amp;lt;head&amp;gt;&amp;lt;/head&amp;gt; tags and, in the case of JDocument::addScript and JHTML::script ensures that a Javascript file is included only once (I.e. there is no .js file duplication).&lt;br /&gt;
&lt;br /&gt;
'''Please Note:''' Joomla 1.6+ may handle MooTools differently than in previous versions. &amp;lt;ref&amp;gt;[http://forum.joomla.org/viewtopic.php?f=502&amp;amp;t=273960 Whitepaper] Upgrade to mootools 1.2&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Components]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Adding_JavaScript</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Adding_JavaScript"/>
				<updated>2012-09-17T13:07:59Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: Restructured this page and provided better documentation for including javascript in Joomla.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
{{cookiejar}}&lt;br /&gt;
&lt;br /&gt;
Javascript (also known as ECMAScript) is a scripting language and is primarily used in client-side web site development to extend and enhance an end-user's experience. Joomla provides developers with easy-to-use mechanisms to include Javascript in their extensions using existing API methods.&lt;br /&gt;
&lt;br /&gt;
There are a number of methods for including Javascript in your Joomla extensions; some of these are described below.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
===Inline Javascript===&lt;br /&gt;
&lt;br /&gt;
Blocks of Javascript code can be declared directly within a component or module's display template using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration addScriptDeclaration] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScriptDeclaration('&lt;br /&gt;
    window.event(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
        alert(&amp;quot;An inline Javascript Declaration&amp;quot;);&lt;br /&gt;
    });&lt;br /&gt;
');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===External Javascript===&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may wish to separate your Javascript into a separate file. Separating your Javascript into an external file can make your template code easier to read especially if the Javascript is lengthy or complex.&lt;br /&gt;
&lt;br /&gt;
There are two ways to include a Javascript file using the Joomla API. The first involves using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript addScript] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScript('/media/system/js/sample.js');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second uses the [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html JHTML] class' [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Add the path parameter if the path is different than 'media/system/js/'&lt;br /&gt;
JHTML::script('sample.js', 'templates/custom/js/');&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The Joomla API's [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods embed Javascript into Joomla's index.php via the jdoc head tag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;head&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] or [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods to embed Javascript includes would result in the index.php rendering the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Calling the class method [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration] would render the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
window.addEvent(&amp;quot;domready&amp;quot;, function() {&lt;br /&gt;
    alert(&amp;quot;Embedded block of JS here&amp;quot;);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using these methods is highly recommended as it clearly differentiates another scripting language (Javascript) from the main PHP code, ensures all Javascript is correctly embedded between the &amp;lt;head&amp;gt;&amp;lt;/head&amp;gt; tags and, in the case of JDocument::addScript and JHTML::script ensures that a Javascript file is included only once (I.e. there is no .js file duplication).&lt;br /&gt;
&lt;br /&gt;
'''Please Note:''' Joomla 1.6+ may handle MooTools differently than in previous versions. &amp;lt;ref&amp;gt;[http://forum.joomla.org/viewtopic.php?f=502&amp;amp;t=273960 Whitepaper] Upgrade to mootools 1.2&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Components]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Adding_JavaScript</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Adding_JavaScript"/>
				<updated>2012-09-17T10:29:51Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{inuse}}&lt;br /&gt;
{{cookiejar}}&lt;br /&gt;
===Adding Javascript===&lt;br /&gt;
----&lt;br /&gt;
This chunk should describe in detail how to add Javascript to the head of&lt;br /&gt;
a template using the Joomla! 1.5 API calls. It should be aimed at&lt;br /&gt;
people who have only minimal knowledge of PHP, HTML and Javascript.&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Components]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:Tutorials]]&lt;br /&gt;
&lt;br /&gt;
Add the following code to have the Javascript library /media/system/js/sample.js included in your template.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScript( '/media/system/js/sample.js' );&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code must be added to your template's template.php file. Usually this file is located at (example): /templates/(theme name)/layouts/template.php&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
Ultimately you are trying to have the resulting HTML page have a Javascript included in the head element (i.e. &amp;lt;head&amp;gt; ... &amp;lt;/head&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Ensure that the Javascript you want to include is in the directory, from the above example:&lt;br /&gt;
   &amp;lt;nowiki&amp;gt;/media/system/js/sample.js&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load your page into a browser and verify that the &amp;lt;script&amp;gt; tag is in the &amp;lt;head&amp;gt; area and able to load the Javascript. Again, using the example: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;http://www.example.com/media/system/js/sample.js&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When successful the script is integrated into your page. Now you can use Javascript in your HTML.&lt;br /&gt;
&lt;br /&gt;
Do not directly add the &amp;lt;script&amp;gt; to your template's index.php. The code will insert the &amp;lt;script&amp;gt; line where your index.php has the following line:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;head&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Add this PHP code to your page, in the head, or next to the Javascript code you will use, depending on your preference.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScript( '/media/system/js/sample.js' );&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Reload and view the page. Ensure that the sample.js is included in the &amp;lt;head&amp;gt; section.&lt;br /&gt;
&lt;br /&gt;
== Adding Javascript Files Using JHTML ==&lt;br /&gt;
You may also use the [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html JHTML] [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] method to add a Javascript file to the head of your document.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$filename = 'filename.js';&lt;br /&gt;
// Add the path parameter if the path is different than 'media/system/js/'&lt;br /&gt;
$path = 'path/to/file/';&lt;br /&gt;
JHTML::script($filename, $path);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
There is a third Boolean argument that can be passed to the script method. Set this to true if you also want MooTools loaded.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$filename = 'filename.js';&lt;br /&gt;
// Add the path parameter if the path is different than 'media/system/js/'&lt;br /&gt;
$path = 'path/to/file/';&lt;br /&gt;
// MooTools will load if it is not already loaded&lt;br /&gt;
JHTML::script($filename, $path, true);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
'''Please Note:''' Joomla 1.6+ may handle MooTools differently than in previous versions. &amp;lt;ref&amp;gt;[http://forum.joomla.org/viewtopic.php?f=502&amp;amp;t=273960 Whitepaper] Upgrade to mootools 1.2&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	<entry>
		<id>http://docs.joomla.org/Setting_up_your_workstation_for_Joomla!_development</id>
		<title>Setting up your workstation for Joomla! development</title>
		<link rel="alternate" type="text/html" href="http://docs.joomla.org/Setting_up_your_workstation_for_Joomla!_development"/>
				<updated>2012-03-12T07:40:38Z</updated>
		
		<summary type="html">&lt;p&gt;Haydenyoung: Update xdebug and xampp versions. Removed information regarding xdebug from 2010.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{RightTOC}}&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
This article provides detailed instructions for setting up your workstation for Joomla! development. Note that there are many possible configurations for doing Joomla! development. Any environment that supports Apache, MySql, PHP, and Subversion should work for writing Joomla! code and extensions.&lt;br /&gt;
&lt;br /&gt;
This document provides step-by-step instructions for setting up and working with Apache, PHP, xdebug, Subversion. This instruction uses Eclipse IDE from chapter 4 and onwards. Please refer to the following links for other development tools:&lt;br /&gt;
&lt;br /&gt;
* [[NetBeans overview]] which also references to a video tutorial of NetBeans&lt;br /&gt;
&lt;br /&gt;
The example used and screenshots are for Windows XP, but the basic steps are the same for Linux.&lt;br /&gt;
&lt;br /&gt;
== Install XAMPP ==&lt;br /&gt;
XAMPP is an easy-to-install package that bundles the Apache web server, PHP, XDEBUG, and the MySql database. This allows you to create the environment you need to run Joomla! on your local machine. The latest version of XAMPP is available at [http://www.apachefriends.org/en/xampp.html the XAMPP web site]. Downloads are available for Linux, Windows, Mac OS X and Solaris. Download the package for your platform. &lt;br /&gt;
&lt;br /&gt;
''Important Note Regarding XAMPP and Skype:'' Apache and Skype both use port 80 as an alternative for incoming connections. If you use Skype, go into the Tools-Options-Advanced-Connection panel and deselect the &amp;quot;Use 80 and 443 as alternatives for incoming connections&amp;quot; option. If Apache starts as a service, it will take 80 before Skype starts and you will not see a problem. But, to be safe, disable the option in Skype.&lt;br /&gt;
&lt;br /&gt;
'''Update'''&lt;br /&gt;
&lt;br /&gt;
''As of August 5, 2010, XDebug has been updated (to version 2.1) which fixes some important bugs (for example, watching local variables for nesting functions). The latest XAMPP package (1.7.3) now includes this new version of XDebug. If you just want to update XDebug, you can download the latest module from [http://www.xdebug.org]. There is a handy website that tells you which XDebug binary you need, depending on your phpinfo() information [http://xdebug.org/find-binary.php here]. To use it, you just copy the output of your phpinfo() display and paste it into the form on the site.''&lt;br /&gt;
&lt;br /&gt;
===Installation on Windows===&lt;br /&gt;
&lt;br /&gt;
Installation for Windows is very simple. You can use the XAMPP installer executable (for example, &amp;quot;xampp-win32-1.7.3-installer.exe&amp;quot;). Detailed installation instructions for Windows are available [http://www.apachefriends.org/en/xampp-windows.html here]. &lt;br /&gt;
&lt;br /&gt;
For Windows, it is recommended to install XAMPP in &amp;quot;c:\xampp&amp;quot; (not in &amp;quot;c:\program files&amp;quot;). If you do this, your Joomla! (and any other local web site folders) will go into the folder &amp;quot;c:\xampp\htdocs&amp;quot;. (By convention, all web content goes under the &amp;quot;htdocs&amp;quot; folder.)&lt;br /&gt;
&lt;br /&gt;
If you have multiple http servers (like IIS) you can change the xampp listening port. In &amp;lt;xamppDir&amp;gt;\apache\conf\httpd.conf, modify the line Listen 80 to Listen [portnumber] (ex: &amp;quot;Listen 8080&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
===Installation on Linux=== &lt;br /&gt;
&lt;br /&gt;
==== Install xammp ====&lt;br /&gt;
Open Terminal and enter: &lt;br /&gt;
 sudo tar xvfz xampp-linux-1.7.7.tar.gz -C /opt&lt;br /&gt;
(replace ''xampp-linux-1.7.7.tar.gz'' with the version of xammp you downloaded).&lt;br /&gt;
It has been reported that the MYSQL database of xampp 1.7.4 does not work with Joomla 1.5.22&lt;br /&gt;
&lt;br /&gt;
This installs ... Apache2, mysql and php5 as well as an ftp server.&lt;br /&gt;
 &lt;br /&gt;
 ''sudo /opt/lampp/lampp start''&lt;br /&gt;
&lt;br /&gt;
and&lt;br /&gt;
 ''sudo /opt/lampp/lampp stop''&lt;br /&gt;
&lt;br /&gt;
starts/stops all the services&lt;br /&gt;
&lt;br /&gt;
==== Test your xammp localhost server ====&lt;br /&gt;
Open your Browser and point it to&lt;br /&gt;
 http://localhost&lt;br /&gt;
The index.php will redirect to&lt;br /&gt;
 http://localhost/xampp&lt;br /&gt;
&lt;br /&gt;
There you will find instructions on how to change default usernames/passwords.  On a PC that does not serve files to the Internet or LAN then changing the defaults is a personal decision.&lt;br /&gt;
&lt;br /&gt;
==== Get Joomla ====&lt;br /&gt;
Download the latest Joomla instalation zip [http://www.joomla.org/download.html]&lt;br /&gt;
&lt;br /&gt;
Unzip to your hard drive&lt;br /&gt;
&lt;br /&gt;
Connect to localhost with an FTP client &lt;br /&gt;
Default&lt;br /&gt;
 nobody&lt;br /&gt;
 lampp&lt;br /&gt;
&lt;br /&gt;
Create a folder for your Joomla on the localhost server&lt;br /&gt;
&lt;br /&gt;
FTP the unpacked Joomla installation files to the newly created Joomla folder. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Important:''' &lt;br /&gt;
* The xammp installation sets the correct Ownership of the files and permissions.&lt;br /&gt;
* Using the '''CHOWN command''' will '''cause Ownership problems with xampp'''.&lt;br /&gt;
* '''Using nautilus''' to manipulate folders/files on localhost will '''cause Ownership problems with xampp'''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Database info'''&lt;br /&gt;
&lt;br /&gt;
Host&lt;br /&gt;
 localhost&lt;br /&gt;
&lt;br /&gt;
Default Database name&lt;br /&gt;
 test&lt;br /&gt;
&lt;br /&gt;
Default Database user&lt;br /&gt;
 root&lt;br /&gt;
&lt;br /&gt;
There is no default Password.&lt;br /&gt;
&lt;br /&gt;
Administrator password is your choice.&lt;br /&gt;
&lt;br /&gt;
Installing Sample Data is recommended for the novice user.&lt;br /&gt;
&lt;br /&gt;
After installation delete the installation directory and point your Browser to:&lt;br /&gt;
 http://localhost/yournewjoomlafolder&lt;br /&gt;
or&lt;br /&gt;
 http://localhost/yournewjoomlafolder/administrator&lt;br /&gt;
&lt;br /&gt;
==== Creating a link in the Ubuntu menu ====&lt;br /&gt;
'''To create a GUI for xammp connected to your Ubuntu menu'''&lt;br /&gt;
&lt;br /&gt;
Open up the Terminal and type&lt;br /&gt;
 sudo gedit /usr/share/applications/xampp-control-panel.desktop&lt;br /&gt;
&lt;br /&gt;
Then copy the following into the gedit and save.&lt;br /&gt;
&lt;br /&gt;
 [Desktop Entry]&lt;br /&gt;
 Encoding=UTF-8&lt;br /&gt;
 Name=XAMPP Control Panel&lt;br /&gt;
 Comment=Start and Stop XAMPP&lt;br /&gt;
 Exec=gksudo &amp;quot;python /opt/lampp/share/xampp-control-panel/xampp-control-panel.py&amp;quot;&lt;br /&gt;
 Icon=/usr/share/icons/Tango/scalable/devices/network-wired.svg&lt;br /&gt;
 Terminal=false&lt;br /&gt;
 Type=Application&lt;br /&gt;
 Categories=GNOME;Application;Network;&lt;br /&gt;
 StartupNotify=true&lt;br /&gt;
&lt;br /&gt;
If the control panel fails to launch, try running the Exec command directly in the terminal:&lt;br /&gt;
&lt;br /&gt;
 gksudo &amp;quot;python /opt/lampp/share/xampp-control-panel/xampp-control-panel.py&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you receive the error:&lt;br /&gt;
&lt;br /&gt;
 Error importing pygtk2 and pygtk2-libglade&lt;br /&gt;
&lt;br /&gt;
Install the missing libraries:&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install python-glade2&lt;br /&gt;
&lt;br /&gt;
=== XDebug PHP debugger ===&lt;br /&gt;
&lt;br /&gt;
The XAMPP package for Linux does not includes the XDebug PHP debugger. To install XDebug on Debian or Ubuntu:&lt;br /&gt;
&lt;br /&gt;
- Install the ''build-essential'' package:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo apt-get update&lt;br /&gt;
sudo apt-get install build-essential&lt;br /&gt;
sudo apt-get install autoconf&amp;lt;/pre&amp;gt;&lt;br /&gt;
- Download the [http://www.apachefriends.org/en/xampp-linux.html development package] for your version of XAMPP and extract it over your existing installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo tar xvfz xampp-linux-devel-1.7.7.tar.gz -C /opt &amp;lt;/pre&amp;gt;&lt;br /&gt;
- Build XDebug:&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://xdebug.org/files/xdebug-2.1.3.tgz&lt;br /&gt;
tar xzf xdebug-2.1.3.tgz&lt;br /&gt;
cd xdebug-2.1.3/&lt;br /&gt;
/opt/lampp/bin/phpize&amp;lt;/pre&amp;gt;&lt;br /&gt;
After this you will have following output on your console…&lt;br /&gt;
&amp;lt;pre&amp;gt;Configuring for:&lt;br /&gt;
PHP Api Version:         20090626&lt;br /&gt;
Zend Module Api No:      20090626&lt;br /&gt;
Zend Extension Api No:   20090626 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;./configure --with-php-config=/opt/lampp/bin/php-config&lt;br /&gt;
make&lt;br /&gt;
sudo make install &amp;lt;/pre&amp;gt;&lt;br /&gt;
Then the output will be this.. please monitor the directory specified.&lt;br /&gt;
&amp;lt;pre&amp;gt;Installing shared extensions:     /opt/lampp/lib/php/extensions/no-debug-non-zts-20090626/ &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a folder in your temp folder that will holds the data file generated by XDebug:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir /opt/lampp/tmp/xdebug&lt;br /&gt;
sudo chmod a+rwx -R /opt/lampp/tmp/xdebug &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternative installations:&lt;br /&gt;
&lt;br /&gt;
Install using PHP extensions community library (PECL) bundled with xampp: &lt;br /&gt;
 sudo /opt/lampp/bin/pecl install xdebug&lt;br /&gt;
&lt;br /&gt;
On Ubuntu/Debian you can install using:&lt;br /&gt;
 apt-get install php5-xdebug &lt;br /&gt;
&lt;br /&gt;
(warning: this will also install Apache and PHP from apt repositories).&lt;br /&gt;
&lt;br /&gt;
'''Warning for 64bit users'''&lt;br /&gt;
&lt;br /&gt;
When compiling XDebug or installing via apt-get, you will receive an error when (re)starting xampp:&lt;br /&gt;
&lt;br /&gt;
 /opt/lampp/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so: wrong ELF class: ELFCLASS64&lt;br /&gt;
&lt;br /&gt;
This is because xampp runs 32bit but XDebug is 64bit. To overcome this problem, either make xdebug.so on a 32bit machine or download it from:&lt;br /&gt;
&lt;br /&gt;
 http://downloads.activestate.com/Komodo/releases/7.0.1/remotedebugging/Komodo-PHPRemoteDebugging-7.0.1-69775-linux-x86.tar.gz&lt;br /&gt;
&lt;br /&gt;
and install it to /opt/lampp/lib/php/extensions:&lt;br /&gt;
&lt;br /&gt;
 wget http://downloads.activestate.com/Komodo/releases/7.0.1/remotedebugging/Komodo-PHPRemoteDebugging-7.0.1-69775-linux-x86.tar.gz&lt;br /&gt;
 sudo tar xzf Komodo-PHPRemoteDebugging-7.0.1-69775-linux-x86.tar.gz&lt;br /&gt;
 cp Komodo-PHPRemoteDebugging-7.0.1-69775-linux-x86/5.3/xdebug.so /opt/lampp/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so&lt;br /&gt;
&lt;br /&gt;
===Installation on Mac OS X===&lt;br /&gt;
Mac OS X actually includes an Apache server out-of-the-box, but most developers will prefer to use the integrated tools and configurability provided by XAMPP.&lt;br /&gt;
&lt;br /&gt;
As with most programs on Mac, installation is a breeze. Visit [http://www.apachefriends.org/en/xampp-macosx.html Apache Friends - Mac OS X] for the universal binary download. &lt;br /&gt;
&lt;br /&gt;
Once the file has finished downloading, just open the disk image, and drag the XAMPP folder to the &amp;quot;Applications&amp;quot; folder alias.&lt;br /&gt;
&lt;br /&gt;
To start the server, open &amp;quot;XAMPP Control.app&amp;quot; and press the start button next to Apache.&lt;br /&gt;
&lt;br /&gt;
=====A Little Troubleshooting=====&lt;br /&gt;
Many Mac users have a little difficulty at this stage when trying to set up another instance of Apache on their machine. If you cannot start XAMPP's Apache, you have two options:&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
'''You can change the listening port of XAMPP.''' In \Applications\XAMPP\xamppfiles\etc\httpd.conf, modify the line that says, &amp;quot;Listen 80&amp;quot; to Listen [portNumber]. E.g.:&lt;br /&gt;
&amp;lt;pre&amp;gt;Listen 8080&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''You can change the listening port of the pre-installed Apache server.''' In finder, go to &amp;quot;/etc&amp;quot; (CMD+SHIFT+G); from here you will be able to navigate through the normally hidden Apache files. Find the folder labeled Apache2, and edit the &amp;quot;http.conf&amp;quot; file. Modify the line that says, &amp;quot;Listen 80&amp;quot; to Listen [portNumber]. E.g.:&lt;br /&gt;
&amp;lt;pre&amp;gt;Listen 8080&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Note: If you choose to change the port of the pre-installed Apache server, you may need to restart your computer for changes to take effect. You will also have to authenticate as an administrator to change these files.''&lt;br /&gt;
&lt;br /&gt;
===Test XAMPP Installation===&lt;br /&gt;
&lt;br /&gt;
Once XAMPP is installed and you have started the Apache service with the XAMPP Control Panel tool, you can test it by opening your browser and navigating to &amp;quot;http://localhost&amp;quot;. You should see the XAMPP welcome screen similar to the one below.&lt;br /&gt;
&lt;br /&gt;
[[Image:xampp_phpinfo_screen.png]]&lt;br /&gt;
&lt;br /&gt;
Select the link called &amp;quot;phpinfo()&amp;quot; in the left-hand menu. This will display a long screen of information about the PHP configuration, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:xampp_phpinfo_conf_file.png]]&lt;br /&gt;
&lt;br /&gt;
At this point, XAMPP is installed successfully. Notice the &amp;quot;Loaded Configuration File&amp;quot; which is highlighted in the screenshot above. We will be editing this file in the next section to configure XDebug.&lt;br /&gt;
&lt;br /&gt;
==Edit PHP.INI File==&lt;br /&gt;
&lt;br /&gt;
====For Windows====&lt;br /&gt;
&lt;br /&gt;
Starting with version 1.7, XAMPP includes the XDebug PHP debugger, but it needs to be configured for use. To do that, we will edit the &amp;quot;php.ini&amp;quot; file to configure XDebug.  The &amp;quot;Loaded Configuration File&amp;quot; in the screenshot above tells you what &amp;quot;php.ini&amp;quot; file is being used. For Windows, this is normally &amp;quot;c:\xampp\apache\bin\php.ini&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;''Important note for Windows 7 &amp;amp; Vista users: As of April 2009 (XAMPP version 1.7.0), the file &amp;quot;php_xdebug.dll&amp;quot; that is included with XAMPP does not work with Windows 7 &amp;amp; Vista. The symptom of this problem is that the Apache server will stop if this version of XDebug is loaded. To correct this problem, download XDebug version &amp;quot;Xdebug 2.0.0 / 5.2 VC6&amp;quot; from the [http://xdebug.org/download.php XDebug website]. This will download a file called &amp;lt;code&amp;gt;php_xdebug-2.0.0-5.2.2.dll&amp;lt;/code&amp;gt;. Save this file in the extensions folder (for example, &amp;lt;code&amp;gt;c:\xampp\php\ext&amp;lt;/code&amp;gt;) and change the php.ini file to point to this file, as shown below. With this file, XDebug works correctly with Windows 7 &amp;amp; Vista, including 64-bit.''&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We need to edit this file to configure XDebug as follows:&lt;br /&gt;
# Find the line &amp;quot;implicit_flush&amp;quot; and set it as follows: &amp;lt;pre&amp;gt;implicit_flush = On&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Find the section called &amp;quot;[Zend]&amp;quot; and comment out all of the lines by putting a semi-colon (&amp;quot;;&amp;quot;) at the start of each line.&lt;br /&gt;
# Find the line: zend_extension = &amp;quot;c:\xampp\php\ext\php_xdebug.dll&amp;quot; and uncomment it out.&lt;br /&gt;
# Find the &amp;quot;[XDebug]&amp;quot; section and uncomment out all of the lines (except for the first comment line). For Windows, it should look like the example below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[XDebug]&lt;br /&gt;
;; Only Zend OR (!) XDebug&lt;br /&gt;
zend_extension_ts=&amp;quot;C:\xampp\php\ext\php_xdebug.dll&amp;quot;&lt;br /&gt;
xdebug.remote_enable=true&lt;br /&gt;
xdebug.remote_host=localhost&lt;br /&gt;
xdebug.remote_port=10000&lt;br /&gt;
xdebug.remote_handler=dbgp&lt;br /&gt;
xdebug.profiler_enable=1&lt;br /&gt;
xdebug.profiler_output_dir=&amp;quot;C:\xampp\tmp&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Windows 7 &amp;amp; Vista, you will use the file downloaded from the XDebug site. So the first line will be&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
zend_extension_ts=&amp;quot;C:\xampp\php\ext\php_xdebug-2.0.0-5.2.2.dll&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For PHP version 5.3 or later, the &amp;quot;_ts&amp;quot; has been dropped, so the first line will read&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
zend_extension=&amp;quot;C:\xampp\php\ext\php_xdebug.dll&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In XAMPP 1.7.3 on Windows 7 (currently not verified/tested with prior Windows versions), XDebug may not work correctly if the path to the DLL file is in quotes.  In this case, the line should be&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
zend_extension = C:\xampp\php\ext\php_xdebug-2.1.0-5.3-vc6.dll&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====For Linux====&lt;br /&gt;
&lt;br /&gt;
We will edit the &amp;quot;php.ini&amp;quot; file to configure XDebug.  The &amp;quot;Loaded Configuration File&amp;quot; in the screenshot above tells you what &amp;quot;php.ini&amp;quot; file is being used. For Linux, it will be something like &amp;quot;/opt/lampp/etc/php.ini&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
We need to edit this file to configure XDebug as follows:&lt;br /&gt;
# Find the line &amp;quot;implicit_flush&amp;quot; and set it as follows: &amp;lt;pre&amp;gt;implicit_flush = On&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Add the following lines at the end:&lt;br /&gt;
&amp;lt;pre&amp;gt;;xDebug Configuration starts&lt;br /&gt;
&lt;br /&gt;
zend_extension = /opt/lampp/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so&lt;br /&gt;
&lt;br /&gt;
xdebug.profiler_output_dir = &amp;quot;/tmp/xdebug/&amp;quot;&lt;br /&gt;
xdebug.profiler_enable = On&lt;br /&gt;
xdebug.remote_enable=On&lt;br /&gt;
xdebug.remote_host=&amp;quot;localhost&amp;quot;&lt;br /&gt;
xdebug.remote_port=10000&lt;br /&gt;
xdebug.remote_handler=&amp;quot;dbgp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;xDebug Configuration ends &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''If using php5-xdebug on Ubuntu'''&lt;br /&gt;
The xDebug Configuration detailed above can be appended to:&lt;br /&gt;
&amp;lt;pre&amp;gt;/etc/php5/apache2/conf.d/xdebug.ini &amp;lt;/pre&amp;gt;&lt;br /&gt;
It should already contain the &amp;quot;zend_extension&amp;quot; variable and only needs the following variables added:&lt;br /&gt;
&amp;lt;pre&amp;gt;xdebug.profiler_enable = On&lt;br /&gt;
xdebug.remote_enable=On&lt;br /&gt;
xdebug.remote_host=&amp;quot;localhost&amp;quot;&lt;br /&gt;
xdebug.remote_port=10000&lt;br /&gt;
xdebug.remote_handler=&amp;quot;dbgp&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tip for users with LAN or remote servers:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;xdebug.remote_host=&amp;quot;localhost&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Should be set to the IP address of your Eclipse workstation [LAN users] or your public IP. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;xdebug.remote_host=192.168.0.199&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====For Mac OS X====&lt;br /&gt;
&lt;br /&gt;
XAMPP for Mac OS X includes the XDebug PHP debugger, but it needs to be added to the &amp;quot;php.ini&amp;quot; file so that XDebug runs when Apache is started. To do this, open up the php.ini file, located at &amp;quot;/Applications/XAMPP/xamppfiles/etc/php.ini&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
We need to edit this file to configure XDebug as follows:&lt;br /&gt;
# Find the line &amp;quot;implicit_flush&amp;quot; and set it as follows: &amp;lt;pre&amp;gt;implicit_flush = On&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Add the following lines at the end:&lt;br /&gt;
&amp;lt;pre&amp;gt;;xDebug Configuration starts&lt;br /&gt;
&lt;br /&gt;
zend_extension=&amp;quot;/Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626/xdebug.so&amp;quot;&lt;br /&gt;
&lt;br /&gt;
xdebug.profiler_output_dir = &amp;quot;/tmp/xdebug/&amp;quot;&lt;br /&gt;
xdebug.profiler_enable = On&lt;br /&gt;
xdebug.remote_enable=On&lt;br /&gt;
xdebug.remote_host=&amp;quot;localhost&amp;quot;&lt;br /&gt;
xdebug.remote_port=10000&lt;br /&gt;
xdebug.remote_handler=&amp;quot;dbgp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
;xDebug Configuration ends &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Be sure to navigate to the directory where you targeted the extension and check to see that the file path is correct. The folders in your XAMPP installation may be named differently.&lt;br /&gt;
&lt;br /&gt;
The current (as of Sept 2010) version of the XAMPP binary for OS X contains the 2.0.4 version of Xdebug which will not let you see the variable data from included files when running xdebug. You can download a newer version from http://code.activestate.com/komodo/remotedebugging/. Unzip and copy one of the xdebug.so files to /Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626. As of Oct 2, 2010 this binary is still out of date (2.1beta3 rather than the stable 2.1) but it will show the variable data appropriately.&lt;br /&gt;
&lt;br /&gt;
===Test XDebug Installation===&lt;br /&gt;
Now, we need to check that XDebug is installed correctly. To do this, we need to re-start XAMPP. In Windows, we can just browse to the &amp;quot;c:\xampp&amp;quot; folder in Windows Explorer and double-click the program &amp;quot;xampp-control.exe&amp;quot; to open the application shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Xampp-control.png]]&lt;br /&gt;
&lt;br /&gt;
Press the &amp;quot;Stop&amp;quot; button for &amp;quot;Apache&amp;quot;. The button with then read &amp;quot;Start&amp;quot;. Press &amp;quot;Start&amp;quot; for Apache and wait a few seconds and the green &amp;quot;Running&amp;quot; message will again display. Then press &amp;quot;Exit&amp;quot; to close the application.&lt;br /&gt;
&lt;br /&gt;
In Windows, if you get &amp;quot;ERROR: MySQL service not started [-1]&amp;quot;, you may be able to correct this by going to c:\xampp\mysql and running mysql_uninstallservice.bat followed by mysql_installservice.bat.&lt;br /&gt;
&lt;br /&gt;
In Linux, to restart XAMPP execute the command&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; sudo /opt/lampp/lampp restart &amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In Mac, open the &amp;quot;XAMPP Control&amp;quot; application, stop, and then start the Apache service again.&lt;br /&gt;
&lt;br /&gt;
Once XAMPP has been restarted, open a browser and navigate to &amp;quot;http://localhost&amp;quot; to display the XAMPP welcome message (if you set XAMPP to listen to another port, you must append the port to the url; e.g.:&amp;quot;http://localhost:8080/&amp;quot;). Press the &amp;quot;phpinfo()&amp;quot; link again to display the PHP information screen. Scroll down to the lower part of the screen. You should see a section for &amp;quot;XDebug&amp;quot; as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Phpinfo_xdebug.png]]&lt;br /&gt;
&lt;br /&gt;
Look at the settings you entered in the &amp;quot;php.ini&amp;quot; file above. You should see these same settings in the xdebug display, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Xdebug settings.png]]&lt;br /&gt;
&lt;br /&gt;
At this point, XDebug is set up correctly.&lt;br /&gt;
&lt;br /&gt;
== Install Eclipse ==&lt;br /&gt;
===Install Java===&lt;br /&gt;
Eclipse is written in Java, so before you can install Eclipse, you need to make sure you have a recent version of Java running. Note that many Linux distributions include third-party Java runtimes (or JVM's for &amp;quot;Java Virtual Machine&amp;quot;), some of which don't work with Eclipse. The safest thing is to make sure you are running the Sun JRE (Jave Runtime Environment). You can download the latest Java version at [http://www.java.com/en/ www.java.com]. If you already have a recent version of the Sun JRE (for example, 1.5 or 1.6), you can skip this step.&lt;br /&gt;
&lt;br /&gt;
Another option for Mac OS X Snow Leopard users is to download the OS X packages from http://www.open.collab.net/downloads/community/ for Subversion after you've installed Subclipse. This will install the appropriate JavaHL library to make the installed JVM work properly.&lt;br /&gt;
&lt;br /&gt;
===Download Eclipse=== &lt;br /&gt;
The next step is to download Eclipse. The easiest thing is to install the Eclipse PDT (PHP Development Tools) &amp;quot;all-in-one&amp;quot; bundle. This is available [http://www.eclipse.org/pdt/downloads/ here]. Download PDT 2.2.0 All In Ones / Eclipse PHP Package. There are downloads for Windows, Linux, and Mac OS X. When you download, you will be asked to pick a download mirror. At the time of this writing, the name of the Windows download is &amp;quot;eclipse-php-helios-win32.zip&amp;quot; and is 143mb.&lt;br /&gt;
&lt;br /&gt;
Installing Eclipse is very easy -- you just unzip the file to a target directory. In Windows, it is best to use a third-party &amp;quot;zip&amp;quot; program to do the unzipping. In some cases, Windows Explorer will not correctly unzip this archive and Eclipse won't run correctly. One good option is 7 Zip, available [http://www.7-zip.org/ here]. &lt;br /&gt;
&lt;br /&gt;
I created a directory called &amp;quot;c:\eclipse_php&amp;quot; for the target. When the file is extracted, you will see a folder called &amp;quot;eclipse&amp;quot; and under that folder 5 folders and six files. &lt;br /&gt;
&lt;br /&gt;
Eclipse will use the default Java JVM for your system. In Windows, this is normally the right one (from Sun). In some Linux distributions, the default JVM may be a third-party program that doesn't work correctly with Eclipse. In this case, you can specify the JVM to use by editing the eclipse.ini file in the eclipse folder as as follows, substituting the correct path to your installed Sun version of the Java JVM:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-showsplash&lt;br /&gt;
org.eclipse.platform&lt;br /&gt;
--launcher.XXMaxPermSize&lt;br /&gt;
512M&lt;br /&gt;
-vm&lt;br /&gt;
/usr/lib/jvm/java-1.5.0-sun/jre/bin/java&lt;br /&gt;
-vmargs&lt;br /&gt;
-Xms512m&lt;br /&gt;
-Xmx512m&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Note that the path to the JVM goes on the line below the &amp;quot;-vm&amp;quot;. Also note that the file ends with a blank line.&lt;br /&gt;
&lt;br /&gt;
At this point, you should be able to start up Eclipse. Just find the &amp;quot;eclipse.exe&amp;quot; file inside the eclipse folder and double-click to execute it. In Linux:  /path/to/your/eclipse/folder/eclipse&lt;br /&gt;
&lt;br /&gt;
==== Eclipse download for Ubuntu====&lt;br /&gt;
:Eclipse can be found in the Ubuntu Software Centre (or Synaptic Package Manager)  and when installed from there it places a menu item in the 'Programming' menu.&lt;br /&gt;
&lt;br /&gt;
===Alternative (Easy) Installation===&lt;br /&gt;
&lt;br /&gt;
An alternative way to install Eclipse with the phpEclipse environment is to use [http://www.easyeclipse.org/site/distributions/php.html EasyEclipse for PHP].  This includes everything you need (including Subclipse) in one simple install for most platforms.  The following instructions are not applicable for EasyEclipse for PHP.&lt;br /&gt;
&lt;br /&gt;
===Create an Eclipse Workspace===&lt;br /&gt;
The first time you launch Eclipse, the screen below displays.&lt;br /&gt;
&lt;br /&gt;
[[Image:eclipse_workspace_default.png]]&lt;br /&gt;
&lt;br /&gt;
Before we can start using Eclipse, we need to create a workspace. This is the folder where all of the Eclipse files and project information will be stored. Since we will be working on web-based projects, we want our project PHP and HTML files to be visible to XAMPP. So we will create our workspace in the &amp;quot;c:\xampp\htdocs&amp;quot; folder (in linux: &amp;quot;/opt/lampp/htdocs&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
To do this, press the Browse button, navigate to the &amp;quot;c:\xampp\htdocs&amp;quot; or &amp;quot;/opt/lampp/htdocs&amp;quot; folder, and press the New Folder button. Create a directory called something like &amp;quot;joomla_development&amp;quot; and make sure it says the same thing in the Folder field. (You can click on a different folder and then click on the new folder to get the name in the Folder field.) The screen should look like the one below.&lt;br /&gt;
&lt;br /&gt;
[[Image:eclipse_workspace_new.png]]&lt;br /&gt;
&lt;br /&gt;
Press OK. Then we go back to the Workspace Launcher, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Eclipse_workspace_created.png]]&lt;br /&gt;
&lt;br /&gt;
Before pressing OK, you can check the box so that you won't need to go through this screen each time you start Eclipse.&lt;br /&gt;
&lt;br /&gt;
Now you should see a splash screen and then a &amp;quot;Welcome to Eclipse&amp;quot; screen, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Eclipse_welcome.png]]&lt;br /&gt;
&lt;br /&gt;
Close this window and the normal Eclipse workbench will display, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Eclipse_workbench.png]]&lt;br /&gt;
&lt;br /&gt;
At this point, Eclipse is installed.&lt;br /&gt;
&lt;br /&gt;
== Configure Eclipse ==&lt;br /&gt;
===Set Newline Character (Windows/Mac Only)===&lt;br /&gt;
Let's  do one final configuration setting, which only applies if you are  running Windows or Mac. As you may know, Windows and Linux use different  characters to terminate lines in text files. Since the Joomla! source  code repository is on a Linux machine, we need to tell Eclipse to create  Linux-style  patch files. Although Mac is Unix based, for the sake of  standardization, Mac users should use these settings too. To do this,  we'll navigate to Window / Preferences, expand the General tree, and  select &amp;quot;Workspace&amp;quot;. This is shown in the screenshot below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Workspace_preferences.png]]&lt;br /&gt;
&lt;br /&gt;
Make two changes. Select Other / UTF-8 for the Text file encoding and Other / Unix for the New text file line delimiter, as shown above. Press OK. &lt;br /&gt;
&lt;br /&gt;
At this point, Eclipse is set up and we can start working with PHP files.&lt;br /&gt;
&lt;br /&gt;
==Configure XDebug==&lt;br /&gt;
''Note: Getting XDebug to work on some workstations can be difficult. XDebug is NOT required to be able to use Eclipse for PHP development. If you are new to Eclipse for PHP, you can skip this section and use Eclipse without XDebug if desired. You can install XDebug later if you need it.''&lt;br /&gt;
&lt;br /&gt;
===Edit XDebug Eclipse Settings===&lt;br /&gt;
The first thing we need to do is to tell Eclipse to use the XDebug we installed earlier. Navigate to Window / Preferences, as shown below. (Mac users: Eclipse / Preferences...)&lt;br /&gt;
&lt;br /&gt;
[[Image:Window_preferences_menu.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This will open the Preferences dialog. Expand the PHP node on the left and select &amp;quot;Debug&amp;quot; to display the screen below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Debug_preferences.png]]&lt;br /&gt;
&lt;br /&gt;
Notice that the &amp;quot;Break at first line&amp;quot; box is checked. This means that the debugger will always break or suspend execution at the first line of code. We'll see this later on when we run the debugger. &lt;br /&gt;
&lt;br /&gt;
Select XDebug for the PHP Debugger. You might get the message below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Debug_port_message.png]]&lt;br /&gt;
&lt;br /&gt;
If so, just ignore it and press OK. (We're going to change the ports now anyway.)&lt;br /&gt;
&lt;br /&gt;
In order to ensure compatability with php.ini, press the &amp;quot;Configure&amp;quot; link for the PHP Debugger to display the screen below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Installed_debuggers.png]]&lt;br /&gt;
&lt;br /&gt;
Highlight the XDebug line and press Configure to display the screen below.&lt;br /&gt;
&lt;br /&gt;
[[Image: Xdebug port.png]]&lt;br /&gt;
&lt;br /&gt;
Change the port number to &amp;quot;10000&amp;quot; as shown, to match what we put in the &amp;quot;php.ini&amp;quot; file earlier. (I also changed the port number for the Zend debugger to &amp;quot;10001&amp;quot; just to get rid of the port 9000 warning message.)&lt;br /&gt;
&lt;br /&gt;
On some systems, you may get Javascript errors like the following: &amp;lt;blockquote&amp;gt;''A Runtime Error has occurred. Do you wish to Debug? Line: 1 Error: Syntax error''&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If so, you can eliminate these messages by changing the &amp;quot;Output Capture Settings / Capture stdout&amp;quot; from &amp;quot;copy&amp;quot; to &amp;quot;off&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Set Debug Options===&lt;br /&gt;
Next, we need to set some options. Select the menu Window / Preferences to open the Preferences dialog. Expand PHP and Debug and select &amp;quot;Workbench Options&amp;quot;, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:workbench_options.png]]&lt;br /&gt;
&lt;br /&gt;
Change the settings as shown above. You can experiment with these settings to make Eclipse best for you.&lt;br /&gt;
&lt;br /&gt;
Next, select the &amp;quot;PHP Servers&amp;quot; item on the tree to display the screen shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:php_servers.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Select the &amp;quot;Default PHP Web Server&amp;quot; (the only one in the list) and press the Edit button to display the Edit Server dialog shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:edit_server.png]]&lt;br /&gt;
&lt;br /&gt;
Recall that we created our workspace, called &amp;quot;joomla_development&amp;quot;, under the &amp;quot;c:\xampp\htdocs&amp;quot; directory. So the URLs to the HTML and PHP files in our project will need to include the &amp;quot;joomla_development&amp;quot; directory name (for example, &amp;quot;http://localhost/joomla_development/Test Project/test.php&amp;quot;). If we change this here, Eclipse will create the URLs for us automatically. So complete the screen as shown above and press OK.&lt;br /&gt;
&lt;br /&gt;
=== Test XDebug ===&lt;br /&gt;
Now we finally get to have some fun. We're going to write a simple PHP script and run and debug it to test that Eclipse is set up correctly. If you are already familiar with Eclipse, you can just skip over this section. If not, we'll go through some basics. &lt;br /&gt;
&lt;br /&gt;
===Eclipse Terminology===&lt;br /&gt;
First, some quick Eclipse terminology. In Eclipse, we talk about the workbench, perspectives, and views. The workbench is just the whole screen. It has an edit area, where we will edit our PHP files, and a series of views around the outside. A view is an area that displays information about a file or some other resource. A perspective is just a pre-packaged layout of views designed for a specific purpose. When we're writing PHP programs, two perspectives are of interest: the PHP perspective and the PHP Debug perspective. &lt;br /&gt;
&lt;br /&gt;
Let's open the PHP perspective. We can select Window / Open Perspective / PHP, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Php_perspectieve_menu.png]]&lt;br /&gt;
&lt;br /&gt;
Now the workbench displays a different set of views, including the PHP Explorer, in the upper left, and three views in the lower left. Note that Eclipse has pretty good Help, which you can access by pressing F1 or selecting Help / Help Contents from the menu. The screen below shows some of the contents available, including Getting Started, Basic Tutorials, and other useful information.&lt;br /&gt;
&lt;br /&gt;
[[Image:Php_help.png]]&lt;br /&gt;
&lt;br /&gt;
===Create a Project===&lt;br /&gt;
Remember that we created a workspace when we launched Eclipse. Before we can write any code, we need to create a project. A project stores a group of related program files. For example, the entire Joomla! application will be one project. We're going to create a test project that we can use to test our setup. We'll select the menu File / New / PHP Project, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:New_project_1.png]]&lt;br /&gt;
&lt;br /&gt;
This will open the first screen in the new project wizard, shown below. Enter the project name, in this case &amp;quot;Test Debug&amp;quot;, and press Finish.&lt;br /&gt;
&lt;br /&gt;
[[Image:New_project_2.png]]&lt;br /&gt;
&lt;br /&gt;
Our new project will now show in the PHP Explorer view. &lt;br /&gt;
&lt;br /&gt;
===Create and Run a PHP File===&lt;br /&gt;
Next, we need to create a PHP file. Select the &amp;quot;Test Debug&amp;quot; project, right click, select New / PHP File, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:New_php_file.png]]&lt;br /&gt;
&lt;br /&gt;
Press the Browse button and select the &amp;quot;Test Project&amp;quot; for the source folder. The New PHP File wizard will display, as shown below. Enter &amp;quot;test.php&amp;quot; for the file name, and press Finish. &lt;br /&gt;
&lt;br /&gt;
[[Image:New_php_file_2.png]]&lt;br /&gt;
&lt;br /&gt;
An empty PHP file will now display in the editor. Enter the code shown below, and press the Save button in the upper left toolbar to save the &amp;quot;test.php&amp;quot; file. &lt;br /&gt;
&lt;br /&gt;
[[Image:Php_test_file.png]]&lt;br /&gt;
&lt;br /&gt;
Now, we're going to execute the script. We'll select the file &amp;quot;test.php&amp;quot; and right-click and select Run As / PHP Web Page, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Run_as_menu.png]]&lt;br /&gt;
&lt;br /&gt;
The script will be run in your default browser, and should display as shown below.&lt;br /&gt;
&lt;br /&gt;
If your php files are set by default to open in a text editor, you may get an error.  If so, go to Window/Preferences/General/Web Browser and explicitly select your preferred option.&lt;br /&gt;
&lt;br /&gt;
[[Image:Run_test_php.png]]&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;quot;phpinfo()&amp;quot; command displays information about your PHP configuration. This is the same screen we saw earlier, when we clicked on the &amp;quot;phpinfo()&amp;quot; link in the XAMPP home page.&lt;br /&gt;
&lt;br /&gt;
===Debug a PHP File===&lt;br /&gt;
Now, let's try debugging this script. Again, select the &amp;quot;test.php&amp;quot; file and right-click, but this time select &amp;quot;Debug As / PHP Web Page&amp;quot;, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Debug_as_web_page.png]]&lt;br /&gt;
&lt;br /&gt;
This time, the browser opens and suspends. (Note: If Eclipse does not suspend at the first line, try closing Eclipse and re-starting it.) &lt;br /&gt;
&lt;br /&gt;
Go back to Eclipse and open the PHP Debug perspective by selecting Window / Open Perspective / PHP Debug, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Open_debug_perspective.png]]&lt;br /&gt;
&lt;br /&gt;
This opens the Debug Perspective, with the &amp;quot;test.php&amp;quot; file suspended, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Debug_perspective.png]]&lt;br /&gt;
&lt;br /&gt;
Recall from earlier that the &amp;quot;Break at first line&amp;quot; option was selected. This is why the debugger has suspended here, on the first line in our program. &lt;br /&gt;
&lt;br /&gt;
There is a lot going on in this screen. The Debug view in the upper left shows the &amp;quot;frame&amp;quot; information. In this case, we are suspended on line 2. The editor window is now in the middle of the screen. A small blue arrow shows where the program is suspended. &lt;br /&gt;
&lt;br /&gt;
In the upper right is the Variables view. This shows the variables that are in scope at this point in the program. &lt;br /&gt;
&lt;br /&gt;
The toolbar in the Debug perspective is important. The tools are labeled below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Debug_toolbar.png]]&lt;br /&gt;
&lt;br /&gt;
*Resume: Resume execution until the next breakpoint or until the program is finished.&lt;br /&gt;
*Terminate: Terminate the debug session. It is important to always terminate the session before trying to run a new session. This must be done even if the browser is closed.&lt;br /&gt;
*Step Into: Used to step into a called function.&lt;br /&gt;
*Step Over: Used to step to the next line.&lt;br /&gt;
&lt;br /&gt;
If you are familiar with debuggers from other IDEs, these commands will probably be familiar. If not, you can read more about it in the Eclipse help documentation and experiment on your own.&lt;br /&gt;
&lt;br /&gt;
To finish, let's press the Step Over button. The Debug view and editor now show that we are on line 3. Note that this means that we are about to execute line 3. Also, note the change in the Variables view. Now the variable $mytest has a value of &amp;quot;this is a test&amp;quot; because line 2 has now executed.&lt;br /&gt;
&lt;br /&gt;
Press Step Over again. Now we're on line 4. Look at the browser window. It should now say &amp;quot;this is a test&amp;quot;, since now line 3 has executed. Press Step Over again and look at the browser window. Now it shows the output of &amp;quot;phpinfo()&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Finally, press Resume. Notice that the program is no longer suspended and the browser no longer shows that it is waiting to complete the page. The script has completed, but our debugger session is still running. &lt;br /&gt;
&lt;br /&gt;
To close the debugger, select the &amp;quot;Remote Launch&amp;quot; in the Debug view and press the Terminate button. Two things happen. In the browser, a new window launches showing a terminate message. In Eclipse, the PHP perspective automatically displays. This is because we set this in the Debug preferences. &lt;br /&gt;
&lt;br /&gt;
Now we had to manually open the Debug perspective, which is an extra step. We can tell Eclipse to do this automatically for us. We just go to Window / Preferences / Run/Debug / Perspectives, select &amp;quot;PHP Web Page&amp;quot;, and check &amp;quot;Always&amp;quot; for &amp;quot;Open the associated perspective when launching&amp;quot;, as shown below. &lt;br /&gt;
&lt;br /&gt;
[[Image:Php_debug_preferences.png]]&lt;br /&gt;
&lt;br /&gt;
At this point, the XDebug is working correctly in Eclipse.&lt;br /&gt;
&lt;br /&gt;
===Troubleshooting Tips===&lt;br /&gt;
====Debugger Doesn't Stop at Breakpoint====&lt;br /&gt;
This can happen if another application is using the port you chose for XDebug. If you experience this problem, try changing the port from 10000 to 10002 or some other value. You have to change the port number in your &amp;lt;code&amp;gt;php.ini&amp;lt;/code&amp;gt; file as well as in the Eclipse preferences. You also have to re-start your Apache server to make the change effective.&lt;br /&gt;
&lt;br /&gt;
== Install Eclipse Subversion ==&lt;br /&gt;
Before we can start coding in Joomla!, we need to be able to work with the Subversion (SVN) source code repository. Subversion is a third-party plugin for Eclipse, so we need to use the Eclipse Update Manager to install it. To do this, navigate to Help / Software Updates, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Eclipse_help_software_updates.png]]&lt;br /&gt;
&lt;br /&gt;
The Software Updates and Add-ons dialog will display. Select the &amp;quot;Available Software&amp;quot; tab. The list of available update sites will display. Press the &amp;quot;Add Site&amp;quot; button to display the Add Site dialog. Enter &amp;quot;http://subclipse.tigris.org/update_1.6.x&amp;quot; as the URL, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Subclipse_update_site_1.6.png]]&lt;br /&gt;
&lt;br /&gt;
Press OK and the &amp;quot;Available Software&amp;quot; tab should again display, this time with additional options from the Subclipse site. Select all Subclipse options as shown below. Then press the &amp;quot;Install&amp;quot; button.&lt;br /&gt;
 &lt;br /&gt;
[[Image:Eclipse_install_update_1.6.png]]&lt;br /&gt;
&lt;br /&gt;
Eclipse will work for a minute and then display the Install window, shown below. Press the &amp;quot;Next&amp;quot; button. A &amp;quot;Review Licenses&amp;quot; window appears. Click &amp;quot;I accept the terms of the license agreements&amp;quot;. Now click finish.&lt;br /&gt;
&lt;br /&gt;
[[Image:Eclipse_install_update2_1.6.png]]&lt;br /&gt;
&lt;br /&gt;
After the files have been downloaded and installed, Eclipse will show the message below recommending that you restart Eclipse. Press &amp;quot;Yes&amp;quot; and Eclipse will restart.&lt;br /&gt;
&lt;br /&gt;
[[Image:Eclipse_install_update3.png]]&lt;br /&gt;
&lt;br /&gt;
Once Eclipse has restarted, we can test that the Subversion plugin is working. Select File / Import as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:File_import.png]]&lt;br /&gt;
&lt;br /&gt;
Then expand the SVN element in the tree. You should see an option called &amp;quot;Checkout Projects from SVN&amp;quot;, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Svn_checkout_projects.png]]&lt;br /&gt;
&lt;br /&gt;
At this point, the plugin has been installed successfully. Press &amp;quot;Cancel&amp;quot; to cancel the import. (We'll import the Joomla! project in the next section.)&lt;br /&gt;
&lt;br /&gt;
== Setting up your workstation for Joomla! development -- Part 2 ==&lt;br /&gt;
This article is continued here: [[Setting up your workstation for Joomla! development -- Part 2]]. This includes checking out the Joomla! source code, debugging Joomla! from Eclipse, creating patch files, and Eclipse tips and tricks.&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Bug Squad]]&lt;/div&gt;</summary>
		<author><name>Haydenyoung</name></author>	</entry>

	</feed>