MySQL 与 SQL 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 站点上。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需在所选字段的末尾、
FROM
子句之前有一个悬空逗号:应该是:
You simply have a dangling comma at the end of the selected fields, before the
FROM
clause:should be:
另一种方法是使用 Magento 类来为您形成查询。
优点是它会自动使用正确的数据库凭据,即使它们发生了更改。如果您想要检索类别名称或任何其他详细信息,您还可以从
$product->getCategoryCollection()
等方法中受益。这种方式确实会产生加载 Magento 的开销,这可能会使您的页面变慢一些。
Another approach would be to use the Magento classes to form the query for you.
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.