3

I started with this exception:

exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1' in /var/www/vhosts/ourdomain.com/httpdocs/lib/Zend/Db/Statement/Pdo.php:236

Used Mysql.php to log SQL to pdo_mysql.log

Found this in the log:

SQL: SELECT `catalog_category_entity`.* FROM `catalog_category_entity` WHERE (entity_id =)

Ran

SELECT `catalog_category_entity`.* FROM `catalog_category_entity` WHERE (entity_id =)

as a query in the database.

Received:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') LIMIT 0, 30' at line 1

So this is the cause of the exception. How do I go about identifying what generates this SQL, and then edit/fix it?

Edit (further info): So entity_id = without the other side of the equation is wrong.

Stack log #10 /var/www/vhosts/ourdomain.com/httpdocs/app/code/core/Mage/Catalog/Block/Product/List.php(80): Mage_Core_Model_Abstract->load(Object(Mage_Catalog_Model_Category))

is:

$category = Mage::getModel('catalog/category')->load($this->getCategoryId());
4

Firstly the ) LIMIT 0, 30 part of the error is likely because you ran the query in PHPMyAdmin which automatically adds that limit clause.

The error here is that (entity_id=) is not valid SQL. SQL expects an integer or a quoted string to follow the comparison operator. So the real question here is how PDO managed to funge this up.

Being that the query that seems to generate this error is SELECT catalog_category_entity.* I believe this to be custom code attempting to incorrectly execute the following statement:

Mage::getModel('catalog/category')->load([id]);

I have tried to replicate this and cannot. There are a number of places where categories are being loaded natively in Magento, so I would venture to say this is an error from custom code which is extending/overwriting Mage_Core_Model_Abstract.

Disable all local modules which rewrite that class and see if the issue persists. If not, follow the standard Magento debugging process and report back.

  • thanks - I can see $category = Mage::getModel('catalog/category')->load($this->getCategoryId()); - would you suggest changing to your example? – Mark P Feb 20 '14 at 16:32
  • Try calling Mage::log($this->getCategoryId()); prior to that line and see what it returns. If it's null, false, or another object that load statement won't work as you're expecting it to and I suggest the next bit of functionality would be to guard code from executing assuming $category is populated. Please follow the standard debug process as linked above and report back with your findings. – philwinkle Feb 20 '14 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.