-1

我有一个要处理的查询,因此我将其格式化为更易于阅读的方式。但是,当我刷新页面时,我收到错误 1064。我唯一做的就是添加换行符。即使我只添加 1 个换行符,我也会收到此错误。

这是原始查询:

$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 . "'";

只需在 FROM 之前添加 1 或 2 个换行符,如下所示:

$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 . "'";

导致出现错误我正在使用带有 mysql 版本 5.5.16 和 php 版本 5.2.2 appache 2.0.63 的 wamp 服务器

4

2 回答 2

2

这是因为您实际上是\n在查询中添加了一个或一个很大的间隙。

如果您在 处停止引号as final_price,然后添加换行符,然后继续字符串. 'from ' . TABLE...,您应该会发现错误不会发生。

在查询后直接键入此代码,您应该会看到错误。

echo $listing_sql;
exit();
于 2012-07-03T13:32:51.220 回答
2

您将换行符放在字符串的中间,mysql 服务器不喜欢这样。将查询分成多行的明智方法是:

$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 . "'";
于 2012-07-03T13:36:03.100 回答