deleteFrom() public method

Create DELETE FROM query
public deleteFrom ( string $table, string $primaryKey = null ) : DeleteQuery
$table string
$primaryKey string
return 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
ファイル: index.php プロジェクト: johonunu/frontend-school
    $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();