2010-10-08 100 views
0

我在尝试从我的数据库中检索信息时收到以下错误:SQL错误AS AS

您的SQL语法错误; 检查对应 你的MySQL服务器版本的 正确的语法使用附近的手册“FROM catalog_product_entity CPE内加入 catalog_product_entity_varchar CPEV O” 第5行

我使用的代码如下;

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>"; 
} 

我想要做的是从magento数据库检索产品以显示在非magento网站上。

回答

2

您只需在选定字段的末尾悬空逗号,在FROM句之前:

cpev.value title, 

应该是:

cpev.value title 
+1

哦,伙计。我准备回家了!哈。谢谢。 :d – doubleplusgood 2010-10-08 15:51:10

0

另一种方法是使用Magento的类为你形成查询。

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()}"); 
} 

好处是它会自动使用正确的数据库凭证,即使它们已更改。如果您想要检索类别名称或其他任何细节,您还可以从$product->getCategoryCollection()等方法中受益。

这种方式的确有加载Magento的开销,这可能会让你的页面变慢一点。