簡體   English   中英

如何在帶有閉包的原始Laravel查詢中使用多個占位符(?)

[英]How to use multiple placeholders (?) in raw Laravel query with in closure

這是我的代碼...

//Database:: find matching results in feeds table
$users_size = $this->holders($this->followed_users_id);
$slugs_size = $this->holders($this->followed_slugs_id);

$match_query = "select * from feeds " .
    "WHERE (user_id IN ($users_size)) " .
    "OR (target_id IN ($slugs_size) AND feedable_type = 'review') " .
    "ORDER BY created_at DESC;";

    $result = DB::select($match_query, $this->followed_users_id, $this->followed_slugs_id);

不用擔心(?)占位符,因為它們是根據需求動態生成的,並且$ this->followed_users_id$this->followed_slugs_id是數組

結果是這個

Connection.php第655行中的QueryException:SQLSTATE [HY093]:無效的參數編號(SQL:從feed中選擇* WHERE(user_id IN(1,17))或(target_id IN(?,?)AND feedable_type ='review')ORDER BY created_at DESC;)

我認為綁定必須在數組中,並作為select方法中的第二個參數

$bindings = array_merge($this->followed_users_id, $this->followed_slugs_id);

$result = DB::select($match_query, $bindings);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM