我有一个已经编写好的 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'