我需要使用 querybuilder 检查 mysql 字段中逗号分隔字符串中是否存在变量。
我这样做
<?php
$parents = DB::table('categorie')>whereRaw('FIND_IN_SET("$categoria->id", parent)')->get();
但没有返回任何值。
最佳答案
您永远不应该自己将变量放入查询中。请改用绑定(bind),这将确保您的参数被正确转义。
<?php
$parents = DB::table('categorie')->whereRaw('FIND_IN_SET(?, parent)', [$categoria->id])->get();
关于php - 在逗号分隔值字段 Laravel 5.1 中查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41458391/