我正在尝试创建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;
});

最佳答案

PK的一部分是university_id和country_id吗?如果是,则Phalcon不允许更改主键。如果您需要这种行为,请从主键中删除这些列,并使用唯一性验证器。

关于php - Phalcon MySQL更新不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37941925/

10-12 05:29