Actions

J3.x

Difference between revisions of "Accessing the database using JDatabase"

From Joomla! Documentation

(Undo revision 79968 by Matthewtbaker (talk) this is a parse error ;))
Line 1: Line 1:
{{underconstruction}}
+
{{incomplete}}
  
 
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.
 
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.
Line 25: Line 25:
 
</source>
 
</source>
  
{{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.
+
{{JVer|3.x}} 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.x core or extension code should use JFactory::getDbo() to obtain a database connection.
  
 
===The Query===
 
===The Query===
Line 182: Line 182:
  
 
====Updating a Record====
 
====Updating a Record====
 +
This is just a simple example to update the params column in the menu table.
 +
<source lang="php">
 +
// Get a db connection.
 +
$db = JFactory::getDbo();
 +
 +
// Create a new query object.
 +
$query = $db->getQuery(true);
 +
 +
//Build the query
 +
$query->update("#__menu");
 +
$query->set('params = '.$db->quote($param));
 +
$query->where('id = '. $db->quote($itemid));
 +
$db->setQuery($query);
 +
 +
//execute db object
 +
try {
 +
// Execute the query in Joomla 3.0.
 +
$result = $db->execute();
 +
} catch (Exception $e) {
 +
//print the errors
 +
print_r($e);
 +
}
 +
</source>
  
 
====Deleting a Record====
 
====Deleting a Record====

Revision as of 04:03, 6 June 2013