cancel
Showing results for 
Search instead for 
Did you mean: 

SQL Statement help?

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

2 REPLIES

Re: SQL Statement help?

I looked in my database and I think the problem is my database uses a prefix..

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