echo full joomla query (with limit etc)? echo full joomla query (with limit etc)? php php

echo full joomla query (with limit etc)?


The JDatabaseQuery object has a __toString() function that outputs the query so you can do:

echo $db->getQuery();

Or if you want to pass it to a function you can explicitly cast it to a string first:

var_dump((string)$db->getQuery());


var_dump($db);die;

Do that after the loadObjectList() call. Inside the $db variable there must be a _sql attribute that is the last query executed.


Agreed with the previous answers, but... In case you are developing your own components, since I often want to know for sure what exactly is executed too, here's a simple solution:

In your models put:

$db = JFactory::getDBO();echo $db->getQuery();

Where you want to know the query... Don't put it in (for example) your view, since it might have loaded some other dropdown list by way of execution in the meantime...

For example:

For a list-view put it right before the foreach ($items... in the public function getItems() of the model.In a form-/item-view put it right before the return $data / return $item in the protected function loadFormData() / public function getItem($pk = null)

Hope this helps...