update() 공개 메소드

Create UPDATE query
public update ( string $table, array | string $set = [], string $primaryKey = null ) : UpdateQuery
$table string
$set array | string
$primaryKey string
리턴 UpdateQuery
예제 #1
0
파일: Database.php 프로젝트: phpf/micro
 /**
  * Performs an update query using FluentPDO
  */
 public function update($table, array $data, $key, $keyValue = null)
 {
     if (!$this->isConnected()) {
         static::connect();
     }
     $this->num_queries++;
     return $this->fpdo->update($table)->set($data)->where($key, $keyValue)->execute();
 }
예제 #2
0
 /**
  * Method used to save entity into it's own database
  *
  * @param Entity $entity
  *
  * @return bool|int|\PDOStatement
  * @throws QueryException
  */
 public function save(Entity $entity)
 {
     $query = null;
     if (intval($entity->getId()) > 0 && !$entity->isForceInsert()) {
         $entity->setDateUpdated(date("Y-m-d H:i:s"));
         $dto = $entity->getDto();
         unset($dto['id']);
         // No need to "update" ID field
         $query = $this->queryBuilder->update($this->getTableName(), $dto, $entity->getId());
     } else {
         $entity->setDateCreated(date("Y-m-d H:i:s"));
         $dto = $entity->getDto();
         $query = $this->queryBuilder->insertInto($this->getTableName(), $dto);
     }
     try {
         $result = $query->execute();
     } catch (\PDOException $ex) {
         throw new QueryException($ex, $query);
     }
     return $result;
 }
예제 #3
0
 public function update($table, $set = [], $primaryKey = null)
 {
     return $this->db->update($table, $set, $primaryKey);
 }
예제 #4
0
    $data = $app->request->post();
    if (empty($data)) {
        $data = json_decode($app->request->getBody(), true);
    }
    $savedId = $fpdo->insertInto('persons', $data)->execute();
    if (!$savedId) {
        throw new \Exception('Saving person failed.');
    }
    $app->render(200, ['saved' => true, 'id' => $savedId]);
});
// PUT /persons/:id
$app->put('/persons/:id', function ($id) use($app, $fpdo) {
    $data = $app->request->post();
    if (empty($data)) {
        $data = json_decode($app->request->getBody(), true);
    }
    $updated = $fpdo->update('persons', $data, $id)->execute();
    if (!$updated) {
        throw new \Exception('Person with id ' . $id . ' does not exist.');
    }
    $app->render(200, ['updated' => true, 'id' => $id]);
});
// DELETE /persons/:id
$app->delete('/persons/:id', function ($id) use($app, $fpdo) {
    $deleted = $fpdo->deleteFrom('persons', $id)->execute();
    if (!$deleted) {
        throw new \Exception('Person with id ' . $id . ' does not exist.');
    }
    $app->render(200, ['deleted' => $deleted]);
});
$app->run();