SQL语法错误附近

时间:2015-01-09 15:18:05

标签: php mysql sql pdo

我正在使用模型来运行这样的查询:

    $tickerHigh = $this->model->ticker('price',$market,'AND buysell=buy','ORDER BY PRICE DESC');

这是我的模特;

    $tickersHigh = $this->db->prepare("SELECT ".$type." FROM trades WHERE market=? " . $buysell  . $order . "");
    $tickersHigh->execute(array(strtolower($market)));
    $tickerHigh = $tickersHigh->fetch();
    if($tickerHigh){
    return $tickerHigh->{$type};    
    }

我收到以下错误:

  

警告:PDOStatement :: execute():SQLSTATE [42000]:语法错误或   访问冲突:1064您的SQL语法有错误;检查   手册,对应右边的MySQL服务器版本   语法使用附近' BY PRICE DESC'

中的第1行

我不确定为什么?

1 个答案:

答案 0 :(得分:2)

只需在ORDER BY之前和AND buysell=buy之前添加一个空格,如下所示:

$tickerHigh = $this->model->ticker("price",$market," AND buysell='buy'"," ORDER BY PRICE DESC");