Wednesday, February 10, 2016

PrestaShop Gamification / Merchant Expertise SQL Errors

No comments:
Quick Note: I added an override to the DbCore class yesterday after discovering that malformed queries fail silently. For example:

<?php
$resource = Db::getInstance()->query(
      "select * frommmmmmmmmmm ps_orders");
while ($data_row = 
      Db::getInstance()->nextRow($resource)) {
   //Do Important Stuff
}

Would simply fail to work, without logging anything.

[Yes, I hear you, I should have checked the value of $resource before starting the while loop, and I agree. However, note that the official PrestaShop docs say that query "Will not return a boolean; instead returns a database resource that you can use with other DB class methods, such as nextRow()". [Ed: Not true! query returns false on SQL syntax errors]]

[I have _PS_MODE_DEV_ on while developing, which catches the error in the example, but my problem was with code that I accidentally typed two letters when my focus was on the wrong window before committing. And yes, I hear you, I should have noticed that when doing my git commit.]

Once I am happy with my override, and the associated iterator I added to make code like the above cleaner and safer, I will blog about the classes. However, in the meantime, I can tell you that my override sends DB errors to the PHP error log, and that the log this morning was filled with stack crawls of SQL errors from the gamification module. I've verified that these errors exist in a virgin install of PrestaShop, and I will use these instructions (thanks, Oskar!) to disable the module.

I also reported the errors.