“0 – SQL=” Error in Joomla

A new client called us yesterday evening and told us that he was seeing the following error on some pages of his Joomla website:

0 – SQL=

The error was in the traditional red layout, immediately followed by the classic “You may not be able to visit this page because of…” message.

The page where the error was appearing was pointing to a custom made component called com_realestate, which was used to display real estates for the area where the visitor is located in (for example, in our case, the extension should show real estate from Montreal).

We checked the extension and we noticed that it wasn’t able to get the location of the visitor based on the IP (the IP to location database was messed up), and so the SQL query being sent to the Joomla database engine was empty (causing the “0 – SQL=” error).

So, how did we fix the problem?

We fixed the problem by ensuring that the extension does not send an empty query to the database if it cannot locate the IP of the visitor. Of course, the extension had deeper issues but it was outside the scope of our work and the client wasn’t interested in fixing them.

Have we seen this problem before?

Yes – we did. It was a few months ago, but back then, the whole Joomla website did not work. It turned out that the problem was in the template itself (the template was sending an empty query to the Joomla database engine).

Are there easier ways to fix the problem?

There are other ways to fix this problem – but none of them is really clean. The thing is, all of them involve modifying Joomla’s own core (which is something we do not really recommend as it might cause conflicts down the road and it’s very possible that the changes might be wiped out by future Joomla updates). If you really want that quick fix, then you can always modify the execute function in the mysqli.php file (assuming you’re using the MySQLi drirver) which is located under the libraries/joomla/database/driver folder to return an empty array if the query is empty. This can be done by adding the following line to the very beginning of the aforementioned function:

if (empty($this->sql)) return array();

Note that doing the above might result in other issues at the extension level if the extension needs to have values from the database and cannot settle with just an empty array (yet another reason why it’s a better idea to fix the problem in the extension rather in Joomla’s own core).

If you have this problem on your Joomla website and you need help fixing the offending extension (whether it’s a plugin/module/component/template), then please contact us. Our fees are affordable, our work is top notch, and we treat every website that we work on as if it’s ours.

No comments yet.

Leave a comment