How to update column with null value

前端 未结 13 667
被撕碎了的回忆
被撕碎了的回忆 2020-12-13 05:08

I am using mysql and need to update a column with a null value. I have tried this many different ways and the best I have gotten is an empty string.

Is there a speci

13条回答
  •  星月不相逢
    2020-12-13 05:47

    On insert we can use

    $arrEntity=$entity->toArray();        
        foreach ($arrEntity as $key => $value) {    
            if (trim($entity->$key) == '' && !is_null($entity->$key) && !is_bool($entity->$key)){
            unset($entity->$key);
            }
        }
    

    On update we can use

    $fields=array();
    foreach ($fields as $key => $value) {
            if (trim($value) == '' && !is_null($value) && !is_bool($value)){
                $fields[$key] = null;
            }
        }
    

提交回复
热议问题