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);

// Dump the query
echo $db->replacePrefix((string) $query);

Will output the following:

SELECT `title` FROM `jos_content`

Get in touch 👋

Feel free to email me about anything. Want some advice? Give some feedback?

You can also reach me around the web: GitHub, LinkedIn, Twitter, DEV, Facebook, Instagram, CodePen