0

I'm receiving the following error with this page while trying to retrieve information from my database;

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 'FROM catalog_product_entity cpe inner join catalog_product_entity_varchar cpev o' at line 5

The code I am using is as follows;

include("conn.php");

//Get all products that are configurable
$query  = "SELECT cpe.entity_id entity,
cpe.sku sku,
cpe.category_ids categories,
cpev.value title,
FROM catalog_product_entity cpe inner join catalog_product_entity_varchar cpev on cpe.entity_id = cpev.entity_id
WHERE cpe.type_id = 'configurable' LIMIT 0,30";
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_assoc($result))
{
    echo "id :{$row['entity']} <br>" .
         "sku :{$row['sku']} <br>" .
         "value :{$row['title']} <br>" .
         "Categories : {$row['categories']} <br>";
} 

What I am trying to do is to retrieve products from a magento database to display on a non-magento site.

2 Answers 2

2

You simply have a dangling comma at the end of the selected fields, before the FROM clause:

cpev.value title,

should be:

cpev.value title
Sign up to request clarification or add additional context in comments.

Comments

0

Another approach would be to use the Magento classes to form the query for you.

require 'app/Mage.php';
Mage::app();

$products = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToFilter('type_id', 'configurable')
    ->setPage(30, 0);

foreach ($products as $product) {
    echo nl2br("id: {$product->getId()}
        sku: {$product->getSku()}
        value: {$product->getTitle()}
        Categories: {$product->getCategoryIds()}");
}

The advantage is it automatically uses the correct database credentials even if they are changed. You also benefit from methods like $product->getCategoryCollection() should you want to retrieve the category names or any other detail.

This way does have the overhead of loading Magento which might make your page a little slower.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.