deleteFrom() 공개 메소드

Create DELETE FROM query
public deleteFrom ( string $table, string $primaryKey = null ) : DeleteQuery
$table string
$primaryKey string
리턴 DeleteQuery
예제 #1
0
파일: Database.php 프로젝트: phpf/micro
 /**
  * Performs a delete query using FluentPDO
  */
 public function delete($table, $key, $keyValue = null)
 {
     if (!$this->isConnected()) {
         static::connect();
     }
     $this->num_queries++;
     return $this->fpdo->deleteFrom($table)->where($key, $keyValue)->execute();
 }
예제 #2
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();