首页 > 解决方案 > 苗条框架上的“更新查询”返回错误

问题描述

我使用 Slim Framework 进行路由和 Postman 更新数据,但它返回“Slim Application Error..”.. 我哪里出错了?在我的插入上它工作得很好

这是我的更新路线

    //Update
    $app->put('/citizens/update/{id}', function (Request $request, Response $response, array $args) {
    $id = $request->getAttribute('id');
    $fName = $request->getParam('f_name');
    $mName = $request->getParam('m_name');
    $lName = $request->getParam('l_name');
    $updateData = Test::update($fName, $mName, $lName, $id);
});

这是我的更新测试类

public static function update($fName, $mName, $lName, $id)
    {
        $db = new DatabaseHandler;
        $updateData = $db->update(TABLE, [
            'f_name' => $fName,
            'm_name' => $mName,
            'l_name' => $lName,
            ])->where(['id' => $id])->save();
        return $updateData;
    }

这是我的更新查询处理程序

public function update($table, $conditions)
    {
        $this->query = "UPDATE ".$table." SET ";
        foreach ($conditons as $column => $val)
        {
            $this->bind[] = $val;
            $this->query = $this->query.$column.'=?';
            if($counter+1 < count($conditions))
            {
                $this->query = $this->query.", ";
            }
            $counter++;
        }
        return $this;
    }
public function where($conditions)
    {
        $this->query = $this->query." WHERE ";
        foreach($conditions as $condition => $val)
        {
            $this->query = $this->query.$condition.'='.$val;
        }
        return $this;
    }

标签: phpslim

解决方案


推荐阅读