代码之家  ›  专栏  ›  技术社区  ›  JahStation

如何更正传递参数/值到whereRaw

  •  0
  • JahStation  · 技术社区  · 2 年前

    我需要用JsonExtract参数化whereRaw中的数据库表和字段:

            $query = $query->whereRaw("JSON_EXTRACT(?, ? ) = ? ", [ "a.tags",'$.' . $orgKey, $orgValue]);
    

    这行不通,这是肯定的:

            $query = $query->whereRaw("JSON_EXTRACT(a.tags, ? ) = ? ", ['$.' . $orgKey, $orgValue]);
    

    我该怎么解决这个问题? 错误,即使查询绑定正确,也会返回此错误:

    SQLSTATE[22032]:<>:3141函数cast_as_JSON的参数1中的JSON文本无效:位置0处的“无效值”。

    0 回复  |  直到 2 年前