更新记录序列化-PHP MySQL

时间:2019-01-22 09:39:40

标签: php mysql serialization

我遇到了这个问题,我必须更新具有序列化列值的表的记录。对该函数的调用有效,并正确传递数据。我可以输入记录,但是不能更新。这是我的代码:

       public function update($user_id, $array_check)
{ 

        $arrayB = array();
        $array_check = unserialize($array_check);

        foreach ($array_check $key => $value) {
            if($value["id"] == $array_check){
                $idRow = $value["id"];

                if($value["value"] == "0"){
                    $valueRow = "1";
                }else{
                    $valueRow = "0";
                }
            }else{
                $idRow = $value["id"];
                $valueRow = $value["value"];
            }

            $row = array("id" => $idRow, "value" => $valueRow);
            $arrayB[] = $row;
        }

        $stmt = $this->_db->prepare('UPDATE data_docs SET docs_selected = :docs_selected WHERE user_id = :user_id');
        $row = $stmt->execute(array(':user_id' => $user_id, ':docs_selected' => serialize($arrayB) ) );

        return $arrayB;

}

1 个答案:

答案 0 :(得分:0)

编辑。

替换此:

           $stmt = $this->_db->prepare('UPDATE data_docs SET docs_selected = :docs_selected WHERE user_id = :user_id);

具有:

           $deseralized = serialize($arrayB);
           $stmt = $this->_db->prepare('UPDATE data_docs SET docs_selected = '$deseralized ' WHERE user_id = '$user_id');