1

我有一个已经编写好的 sql 查询,但是 from 命令是小写的。我喜欢它的格式为大写,但如果我更改它,我会收到错误 1064。

select、where 等也是小写字母,但是当我更改为大写字母时,它们工作正常,只有 WHERE 语句会导致这种情况。

这是sql:

 $listing_sql = "SELECT " . $select_column_list . 
                        "p.products_id, p.products_model, p.manufacturers_id, p.products_price, " .
                        "p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as " .
                        "specials_new_products_price, IF(s.status, s.specials_new_products_price, " .
                        "p.products_price) as final_price ". 
                        "FROM " . 
                        TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p left join " . 
                        TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id left join " . 
                        TABLE_SPECIALS . " s on p.products_id = s.products_id, " . 
                        TABLE_PRODUCTS_TO_CATEGORIES . " p2c WHERE p.products_status = '1' AND " .
                        "p.products_id = p2c.products_id and pd.products_id = p2c.products_id and " .
                        "pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . 
                        (int)$current_category_id . "'";

以下是回显时 sql 的样子:

SELECT p.products_image,
       pd.products_name,
       p.products_id,
       p.products_model,
       p.manufacturers_id,
       p.products_price,
       p.products_tax_class_id,
       IF(s.status, s.specials_new_products_price, NULL)             AS
       specials_new_products_price,
       IF(s.status, s.specials_new_products_price, p.products_price) AS
       final_price
FROM   products_description pd,
       products p
       LEFT JOIN manufacturers m
              ON p.manufacturers_id = m.manufacturers_id
       LEFT JOIN specials s
              ON p.products_id = s.products_id,
       products_to_categories p2c
WHERE  p.products_status = '1'
       AND p.products_id = p2c.products_id
       AND pd.products_id = p2c.products_id
       AND pd.language_id = '1'
       AND p2c.categories_id = '36' 
4

2 回答 2

1

(有根据的)猜测是您正在谈论 OsCommerce 安装。

如果不是这种情况,您可能正在使用曾经从它分叉出来的东西(或其前身 tep

您遇到的问题可能是因为 splitPageResults类中的构造函数使用strpos区分大小写的 ,而不是stripos不区分大小写的 。

所以...总之,它是,

如果这确实是 oscommerce:

编辑两个 split_page_results.php 文件
(1:/catalog/classes/split_page_results.php,2:/catalog/admin/classes/split_page_results.php)

并在构造函数中用 stripos 替换 strpos。

即改变

$pos_from = strpos($this->sql_query, ' from', 0);

至...

$pos_from = stripos($this->sql_query, ' from', 0);

如果这不是 osCommerce,只需寻找类似的东西。

strpoststripos的 php 文档

于 2012-10-30T13:43:28.190 回答
0

尝试加入产品:

SELECT p.products_image,
   pd.products_name,
   p.products_id,
   p.products_model,
   p.manufacturers_id,
   p.products_price,
   p.products_tax_class_id,
   IF(s.status, s.specials_new_products_price, NULL) AS specials_new_products_price,
   IF(s.status, s.specials_new_products_price, p.products_price) AS final_price
FROM   products_description pd
   LEFT JOIN manufacturers m
          ON p.manufacturers_id = m.manufacturers_id
   LEFT JOIN specials s
          ON p.products_id = s.products_id,
            products_to_categories p2c
   LEFT JOIN products p ON ( p.products_id = p2c.products_id )
WHERE  p.products_status = '1'
   AND p.products_id = p2c.products_id
   AND pd.products_id = p2c.products_id
   AND pd.language_id = '1'
   AND p2c.categories_id = '36' 
于 2012-07-04T12:24:25.657 回答