【问题标题】:Laravel framework is clashing with SQL where-inLaravel 框架与 SQL where-in 发生冲突
【发布时间】:2018-09-01 05:52:08
【问题描述】:

使用 Laravel 框架。看起来 Where-In sql 查询与框架发生冲突。我错了,如果没有任何解决方法?

    //terms is the search string sent to server. 
    //Am breaking it up into searchable tags.
    $terms = explode(" ", $term);

    $posts = DB::select('SELECT * FROM car
    WHERE model IN ?',
    implode(',',$terms));

错误:

prepareBindings() must be of the type array, string given

【问题讨论】:

    标签: sql laravel where-in


    【解决方案1】:

    你能试试吗 $posts = DB::select('SELECT * FROM car WHERE model IN (?)', [implode(',',$terms)]); 并报告

    我已更新答案以反映对您有用的方法。

    【讨论】:

    • SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以了解在“?”附近使用的正确语法在第 2 行(SQL:SELECT * FROM car\n ◀ WHERE model IN ford)
    • 什么玩意儿。以下作品。 $posts = DB::select('SELECT * FROM car WHERE model IN (?)', [implode(',',$terms)]);
    • 为什么不 DB::table('car')->whereIn('model', $array); ?还是只是 DB::RAW ?
    猜你喜欢
    • 2016-07-23
    • 1970-01-01
    • 2016-03-10
    • 1970-01-01
    • 2014-06-29
    • 1970-01-01
    • 2019-07-15
    • 2012-10-05
    • 2015-04-01
    相关资源
    最近更新 更多