2013-02-05 17 views
0

你好我想如下因素的脚本来从Magento的数据库中的数据,但我grttinf如下因素误差误差在MySQL语法在Magento

您的SQL语法错误;检查对应于你的MySQL服务器版本使用附近的正确语法手册“:描述--104:元描述--506:的Anahi的提示--1067:大小&飞度”在第15行

$conn1 = mysql_pconnect("db.aviesta.com","gys",'d3v3l0p3r$') or die ("Error In Connetion Databse" . mysql_error()); 
mysql_select_db("customer_transaction_dev",$conn1); 
//db Connection end 
$select=mysql_query("SELECT DISTINCT A.entity_id AS productID, 
A.sku, A.created_at, B.value AS Price, 
C.value AS Description, 
E.qty AS Quantity, 
F.stock_status, 
H.Value AS imageURL 
FROM catalog_product_entity A 
INNER JOIN catalog_product_entity_decimal B 
ON A.entity_id=B.entity_id AND B.store_id=5 
INNER JOIN catalog_product_entity_varchar C 
ON A.entity_id=C.entity_id AND C.attribute_id=105 --Description 
INNER JOIN catalog_product_entity_text D 
ON A.entity_id=D.entity_id 
AND D.attribute_id= 97 
--97: Description 
--104: Meta Description 
--506: Anahi's Tip 
--1067: Size & Fit 
--1068: Style Ideas 
INNER JOIN cataloginventory_stock_item E 
ON A.entity_id=E.product_id 
INNER JOIN cataloginventory_stock_item F 
ON A.entity_id=F.product_id AND F.website_id=2 
INNER JOIN catalog_product_relation G 
ON A.entity_id=G.parent_id 
INNER JOIN catalog_product_entity_varchar H 
ON A.entity_id=H.entity_id 
AND H.attribute_id =106 --Image 
WHERE A.attribute_set_id IN (70,71) 
AND A.entity_id=26179' ") or die(mysql_error()); 

请告诉我我在做什么错误

回答

3

双点划线注释需要以下空格。

WRONG:

--97: Description 

RIGHT:

-- 97: Description 

http://dev.mysql.com/doc/refman/5.5/en/comments.html


回复您的评论:

WHERE A.attribute_set_id IN (70,71) 
AND A.entity_id=26179' 

您在查询的第30行的WHERE子句末尾有一个零散的单引号。 SQL语法分析器从SQL语句的开始处开始计算行数,而不是从文件的开始处开始计算。


其中Image发生的唯一的地方是在这里:

ON A.entity_id=H.entity_id 
AND H.attribute_id =106 --Image 

这是你所需要的双横线注释后的空间另一种情况。

似乎也可以在查询前面多了一个这样的案例:

ON A.entity_id=C.entity_id AND C.attribute_id=105 --Description 

我测试的查询对一些空表,有一次我通过添加空格纠正所有意见,查询工作。

+0

现在它会引发此错误您的SQL语法中有错误;检查对应于你的MySQL服务器版本的手册,在第30行第30行'''附近使用正确的语法。A.antity_id = E.product_id在我的文件中 –

+0

我认为迄今为止您提供的解决方案非常棒,但是现在我在'on子句'错误中遇到了未知列'Image' –