Actions

Difference between revisions of "JFactory/getDBO"

From Joomla! Documentation

(Fix red links)
(See also)
 
(2 intermediate revisions by 2 users not shown)
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>
Line 14: Line 14:
 
</pre>
 
</pre>
 
===See also===
 
===See also===
* [http://api.joomla.org/Joomla-Framework/JFactory.html#getDBO JFactory->getDBO on api.joomla.org]
+
* [http://api.joomla.org/cms-3/classes/JFactory.html#method_getDbo JFactory->getDBO on api.joomla.org]
* [http://api.joomla.org/Joomla-Platform/Database/JDatabase.html JDatabase]
+
* [http://api.joomla.org/cms-3/classes/JDatabase.html JDatabase]
 +
* [http://api.joomla.org/cms-3/classes/JDatabaseDriver.html JDatabaseDriver]
 +
 
 
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JFactory]]</noinclude>
 
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JFactory]]</noinclude>

Latest revision as of 02:48, 28 November 2014

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