Actions

Difference between revisions of "JFactory/getDBO"

From Joomla! Documentation

(New page: 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 getDB...)
 
m (Replaced =& with =)
 
(One intermediate revision by one user not shown)
Line 1: Line 1:
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]].
+
Returns a reference to the global database object, only creating it if it doesn't already exist.  The object returned will be of type [http://api.joomla.org/Joomla-Platform/Database/JDatabase.html JDatabase].
 
===Syntax===
 
===Syntax===
object [[JDatabase]] getDBO()
+
object [http://api.joomla.org/Joomla-Platform/Database/JDatabase.html JDatabase] getDBO()
  
 
===Example===
 
===Example===
 
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 15: Line 15:
 
===See also===
 
===See also===
 
* [http://api.joomla.org/Joomla-Framework/JFactory.html#getDBO JFactory->getDBO on api.joomla.org]
 
* [http://api.joomla.org/Joomla-Framework/JFactory.html#getDBO JFactory->getDBO on api.joomla.org]
* [[JDatabase]]
+
* [http://api.joomla.org/Joomla-Platform/Database/JDatabase.html JDatabase]
 
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JFactory]]</noinclude>
 
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JFactory]]</noinclude>

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