Skip to content

Instantly share code, notes, and snippets.

@janich
Created February 19, 2013 08:42
Show Gist options
  • Save janich/4984102 to your computer and use it in GitHub Desktop.
Save janich/4984102 to your computer and use it in GitHub Desktop.
Ugly, but helpfull!
function q($query) {
echo "<pre>";
$q = str_replace("#__", JFactory::getConfig()->get('dbprefix'), (string) $query);
var_dump($q);
echo "</pre>";
}
@nikosdion
Copy link

Don't reinvent the wheel, Janich:

function q($query) {
$db = JFactory::getDbo();
echo "

";
var_dump(JFactory::getDbo()->replacePrefix($query));
echo "
";
}

You can also use JLog instead of var_dump (neater) or turn on Debug System (it logs all queries going through JDatabaseDriver, additionally showing them in the debug module).

@mbabker
Copy link

mbabker commented Feb 19, 2013

If you don't mind the prefix remaining, I always just echo (string) $query;

@janich
Copy link
Author

janich commented Feb 19, 2013

I guess it wasn't really about the method, but about having an easy way to echo out a query with the correct prefixes while developing.

Heh, yeah, it probably is bit overkill. Larger/complex queries should probably be kept in a SQL editor until 'ready' ;)

@twentronix
Copy link

It's still on my TODO to check out the Joomla extension J!Dump, so I can't say how handy it is, but it looks promising:
http://extensions.joomla.org/extensions/miscellaneous/development/1509

I also use var_dump. If you view the source you don't need to add the pre tags, but the pre tags are indeed necessarily if you want to view it in readable html format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment