- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2017
06:43 PM
01-12-2017
06:43 PM
SQL Statement help?
I am new to programming, but I don't know why this statement isn't working
$connection = Mage::getSingleton('core/resource')->getConnection('core_read'); $sql = <<<SQL SELECT `value` FROM catalog_product_entity_int WHERE entity_id = {$product->getId()} AND attribute_id = {$code} SQL; $row = $connection->fetchRow($sql); return $row['value']; }
I am getting this error:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'tikit706_mage899.catalog_product_entity_int' doesn't exist, query was: SELECT `value` FROM catalog_product_entity_int WHERE entity_id = 1 AND attribute_id = 133
Labels:
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2017
06:44 PM
01-12-2017
06:44 PM
Re: SQL Statement help?
I looked in my database and I think the problem is my database uses a prefix..
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2017
05:19 AM
01-13-2017
05:19 AM
Re: SQL Statement help?
Yes, if you use a prefix it won't work as you are hard coding the table name into the query.
Your code example suggests that you already have the product object loaded so no need to go to the DB again. Just grab the attribute using $product->getAttribute() (change the getAttribute() to whatever the attribute is you want i.e. $product->getSize().
Richard Cleverley
Magepim Ecommerce Services
Magepim Ecommerce Services