[英]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.