Actions

Difference between revisions of "JFactory/getDBO"

From Joomla! Documentation

(Fix red links)
m (Replaced =& with =)
 
Line 6: Line 6:
 
In this example, the Joomla database prefix is retrieved.
 
In this example, the Joomla database prefix is retrieved.
 
<source lang="php">
 
<source lang="php">
$db =& JFactory::getDBO();
+
$db = JFactory::getDBO();
 
echo "Database prefix is : " . $db->getPrefix();
 
echo "Database prefix is : " . $db->getPrefix();
 
</source>
 
</source>

Latest revision as of 16:12, 20 November 2013

Returns a reference to the global database object, only creating it if it doesn't already exist. The object returned will be of type JDatabase.

Syntax

object JDatabase getDBO()

Example

In this example, the Joomla database prefix is retrieved.

$db = JFactory::getDBO();
echo "Database prefix is : " . $db->getPrefix();

which should output something like this:

Database prefix is : jos_

See also