[英]Where clause error in passing parameter to laravel 5 query builder
我使用以下查询获取数据。 当我将参数传递给where
子句时,它将参数转换为问号?
。
$productDatas = DB::table('products')
->select('products.*','products.id as pid','product_features.*','product_features.id as pfid')
->join('product_features','product_features.product_id','=','products.id')
->join('categories','categories.id','=','products.cat_id','left');
if($value == 13) {
// $value = intval($value);
$productData = $productDatas->where('product_features.'.$field,'<',$value)->toSql();
dd($productData);
} else {
$productData = $productDatas->where('product_features.'.$field,'=',$value)->get();
}
输出查询:
"select `products`.*, `products`.`id` as `pid`, `product_features`.*, `product_features`.`id` as `pfid`
from `products`
inner join `product_features` on `product_features`.`product_id` = `products`.`id`
left join `categories` on `categories`.`id` = `products`.`cat_id`
where `product_features`.`primary_camera` < ?"
不用担心?
标记。 这是laravel如何表明你将在哪个位置动态分配值?
是。
要在您对应的路径文件中完整演示,请放置以下代码并运行代码。
\DB::listen(function ($sql, $bindings, $time) {
dump($sql);
dump($time);
dump($bindings);
});
这将显示将放置在哪些地方的$bindings
?
是。 此外,您可以列出查询执行$time
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.