MySQL 与 SQL AS 错误

发布于 2024-09-26 20:35:13 字数 921 浏览 0 评论 0原文

我在尝试从数据库检索信息时收到此页面的以下错误;

您的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

追星践月 2024-10-03 20:35:13

您只需在所选字段的末尾、FROM 子句之前有一个悬空逗号:

cpev.value title,

应该是:

cpev.value title

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
巴黎盛开的樱花 2024-10-03 20:35:13

另一种方法是使用 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 的开销,这可能会使您的页面变慢一些。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文