Phalcon MySQL UPDATE无效

时间:2016-06-21 10:27:54

标签: php mysql phalcon

我正在尝试创建RESTful API,我正在尝试通过纯查询通过Phalcon更新我的MySQL数据库行。但是我遇到了运行查询的问题Phalcon status->success()返回true,但是当我查看db值与之前相同时。

我尝试从SQL查询更改为使用model->update(),但遇到了同样的问题。值country_iduniversity_id都是整数。

任何线索或解决方法?

我的POST处理功能:

$app->post("/api/user/university/{id:[0-9]+}", function($id) use ($app){

    $university_id = $app->request->getPost("university_id");

    $country_id = universities::findFirstById($university_id)->country_id;

    $phpql = "UPDATE users 
                SET university_id=:university_id:,
                    country_id=:country_id:
                WHERE 
                    id=:user_id:";

    $status = $app->modelsManager->executeQuery($phpql, array(
        'user_id' => $id,
        'university_id' => $university_id,
        'country_id' => $country_id     
    ));


    $response = new Response();

    if($status->success() == true){
        $response->setStatusCode(201, "Created");


        $response->setJsonContent(
            array(
                'status' => 0
            )
        );
    } else {

        $response->setStatusCode(409, "Conflict");

        $errors = array();
        foreach ($status->getMessages() as $message) {
            $errors[] = $message->getMessage();
        }

        $response->setJsonContent(
            array(
                'status'   => 'ERROR',
                'messages' => $errors
            )
        );
    }
    return $response;
});

1 个答案:

答案 0 :(得分:0)

university_id和country_id是PK的一部分吗?如果是,则phalcon不允许更改原始密钥。如果您需要这样的行为,请从原始密钥中删除这些列并使用uniquness验证器。