Php 添加换行符时出现SQL错误1064
我有一个我想处理的查询,所以我以一种更容易阅读的方式格式化了它。但是,当我刷新页面时,我收到错误1064。我唯一做的就是添加换行符。即使我只添加了一个换行符,我也会得到这个错误 以下是原始查询:Php 添加换行符时出现SQL错误1064,php,mysql,Php,Mysql,我有一个我想处理的查询,所以我以一种更容易阅读的方式格式化了它。但是,当我刷新页面时,我收到错误1064。我唯一做的就是添加换行符。即使我只添加了一个换行符,我也会得到这个错误 以下是原始查询: $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.
$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 . "'";
只需在前面添加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 server,这是因为您实际上在查询中添加了一个\n或一个很大的间隙 如果您以最终价格停止报价,然后添加换行符,然后继续字符串从'。表…,您应该会发现错误没有发生 直接在查询后键入此代码,您将看到错误
echo $listing_sql;
exit();
你把换行符放在字符串中间,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 . "'";
这不是答案,但为什么在int表达式周围使用引号呢?查看执行查询的代码可能也会有所帮助。这不是我的查询,但我相信这是因为它是一个被调用到querySee中的php变量,实际上查询使用WHERE x='3'而不是WHERE x=3形式;但是,如果x是int域,那么后者是很好的,我想它是。但不管怎样:您是否尝试在其行的“from”之前插入一个空格?即,将^from替换为^from。