Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 当所述列';s值为空?_Mysql_Json_Laravel - Fatal编程技术网

Mysql 当所述列';s值为空?

Mysql 当所述列';s值为空?,mysql,json,laravel,Mysql,Json,Laravel,我有一个where语句,其中包含一个JSON_extract方法。JSON_提取使用一个名为new_value或old_value的可空列。如果列包含JSON字符串,则检查有效,但当列为NULL时,where语句得到确认 ->where(function($query) use ($other_key, $new_change) { $query->where(DB::raw('json_extract(old_value, "$.theme_id") = 1))

我有一个where语句,其中包含一个JSON_extract方法。JSON_提取使用一个名为
new_value
old_value
的可空列。如果列包含JSON字符串,则检查有效,但当列为NULL时,where语句得到确认

->where(function($query) use ($other_key, $new_change) {
        $query->where(DB::raw('json_extract(old_value, "$.theme_id") = 1))
            ->orWhere(DB::raw('json_extract(new_value, "$.theme_id") = 1));
new\u值
old\u值
为NULL时,返回该行,但NULL的主题id显然不等于1。有人能解释一下这里发生了什么吗?

这是:

->where(function($query) use ($other_key, $new_change) {
    $query->where(DB::raw('json_extract(old_value, "$.theme_id") = 1))
        ->orWhere(DB::raw('json_extract(new_value, "$.theme_id") = 1));
应该是:

->where(function($query) use ($other_key, $new_change) {
    $query->where(DB::raw("json_extract(old_value, '$.theme_id')"), 1);
        ->orWhere(DB::raw("json_extract(new_value, '$.theme_id')"), 1);
这就是Laravel中where语句的工作原理。我没有插入第二个参数,这就是为什么Laravel认为我在检查NULL。现在可以了,为我的愚蠢道歉