一个sql查询已经在托管上运行良好,但在WAMP上无法正常工作

时间:2014-02-01 20:46:29

标签: mysql sql


我有一个sql查询已经在托管上工作得很好,但在WAMP上我没有得到SQL错误1064,请帮忙。
谢谢!

$query = 'SELECT p.products_id, p.products_image, p.products_tax_class_id, p.products_ordered, IF (s.status, s.specials_new_products_price, NULL) AS specials_new_products_price, p.products_price, pd.products_name, p.products_model';


    if ( defined('FEATURED_MODUL_SPECIALS_ONLY') AND FEATURED_MODUL_SPECIALS_ONLY == 'true' ) {
            $query .= 'FROM ' . TABLE_SPECIALS . ' s LEFT JOIN ' . TABLE_PRODUCTS . ' p ON s.products_id = p.products_id ';
    } else {
            $query .= 'FROM ' . TABLE_PRODUCTS . ' p LEFT JOIN ' . TABLE_SPECIALS . ' s ON p.products_id = s.products_id ';
    }
    if ($current_page != FILENAME_DEFAULT)  { 
        $query .= 'LEFT JOIN ' . TABLE_PRODUCTS_DESCRIPTION . " pd ON p.products_id = pd.products_id AND pd.language_id = '" . $languages_id . "'
        LEFT JOIN " . TABLE_FEATURED . " f ON p.products_id = f.products_id
        WHERE p.products_status = '1' AND f.status = '1' order by rand($mtm) DESC limit " . FEATURED_MODUL_MAX_DISPLAY;
    }else{
        $query .= 'LEFT JOIN ' . TABLE_PRODUCTS_DESCRIPTION . " pd ON p.products_id = pd.products_id AND pd.language_id = '" . $languages_id . "'
        LEFT JOIN " . TABLE_FEATURED . " f ON p.products_id = f.products_id
        WHERE p.products_status = '1' AND f.status = '1' order by rand($mtm) DESC limit " . FEATURED_MODUL_MAX_DISPLAY_FIRST_PAGE;
    }

我在WAMP服务器上出错了:
1064 - 您的SQL语法出错;查看与您的MySQL服务器版本对应的手册,以便在'p LEFT JOIN specials s on p.products_id = s.products_id LEFT JOIN products_descr'第1行附近使用正确的语法

SELECT p.products_id,p.products_image,p.products_tax_class_id,p.products_ordered,IF(s.status,s.specials_new_products_price,NULL)AS specials_new_products_price,p.products_price,pd.products_name,p.products_modelFROM products p LEFT JOIN特价s ON p.products_id = s.products_id LEFT JOIN products_description pd ON p.products_id = pd.products_id AND pd.language_id ='1'LEFT JOIN feature f ON p.products_id = f.products_id WHERE p.products_status ='1' AND f.status ='1'由rand(12852)DESC限制12

[TEP STOP]

1 个答案:

答案 0 :(得分:0)

我不知道查询是如何工作的。第一个字符串是:

'SELECT p.products_id, p.products_image, p.products_tax_class_id, p.products_ordered, IF (s.status, s.specials_new_products_price, NULL) AS specials_new_products_price, p.products_price, pd.products_name, p.products_model'

然后第二个是:

'FROM ' . TABLE_SPECIALS . ' s LEFT JOIN ' . TABLE_PRODUCTS . ' p ON s.products_id = p.products_id '

'FROM ' . TABLE_PRODUCTS . ' p LEFT JOIN ' . TABLE_SPECIALS . ' s ON p.products_id = s.products_id '

在这两个中,select列表如下所示:

'p.process_modelFROM '

我怀疑这是表中的一列。我怀疑该查询也缺少from子句。

将空格放回select行的末尾,查询应该有效。

在编译器的第一次传递期间,您将遇到特定错误。它找到关键字left join,但它们不在from子句中。