2016-06-21 90 views
1

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

我试图从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; 
}); 

回答

0

是PK的university_id和COUNTRY_ID一部分?如果是,那么phalcon不允许更改原始密钥。如果你需要这样的行为,从初始密钥中删除这些列并使用独特验证器。

+0

这应该是我对我的白痴抱歉.... – Mrnda