DEV Community

loading...

Print the raw query from dbo for debugging Joomla

Daniel Felix
Senior software engineer ❯ Experienced PHP Developer ❯ Laravel Expert ❯ WordPress ❯ Joomla❯ Js❯ AWS ❯ Continuous learner.
Originally published at danielfelix.in ・1 min read

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

Discussion (0)