FIND_IN_SET查询无法在laravel 5.7中运行

时间:2019-07-12 07:31:12

标签: mysql laravel

我在上述查询的accepted_join_id中发现输入的user_id给出错误,因为 语法错误,意外的'$ user_id'(T_VARIABLE)

$query=DB::select('select activity_id,accepted_join_id from table_user_create_activity WHERE FIND_IN_SET('$user_id',?) and activity_id=?',[$user_id,$accepted_join_id]);

1 个答案:

答案 0 :(得分:0)

如果您想将php中的$ user_id值注入查询中,请尝试以下操作:

$query=DB::select('select activity_id,accepted_join_id from table_user_create_activity WHERE FIND_IN_SET('.$user_id.',?) and activity_id=?',[$user_id,$accepted_join_id]);

或者如果$ user_id在查询中,则应为:

$query=DB::select('select activity_id,accepted_join_id from table_user_create_activity WHERE FIND_IN_SET("$user_id",?) and activity_id=?',[$user_id,$accepted_join_id]);