DEV Community

Daniel Felix
Daniel Felix

Posted on • Originally published at danielfelix.in

Print the raw query from dbo for debugging Joomla

We can use Joomla's replacePrefix function which dumps out the query in a format that can be inserted straight into the likes of phpMyAdmin.

Here's a simple example:

$db = JFactory::getDbo();

$query = $db->getQuery(true);
$query->select($db->quoteName('title'))
      ->from($db->quoteName('#__content'));
$db->setQuery($query);

// Dump the query
echo $db->replacePrefix((string) $query);
Enter fullscreen mode Exit fullscreen mode

Will output the following:

SELECT `title` FROM `jos_content`
Enter fullscreen mode Exit fullscreen mode

Top comments (0)