function doesAccountExists($accountID) { global $link; if (intval($accountID) <= 0) { Response::NotFound("Account with ID {$accountID} does not exists."); } $query = "SELECT * FROM accounts WHERE accountID={$accountID}"; $ret = mysqli_query($link, $query); $num_rows = mysqli_num_rows($ret); if ($num_rows <= 0) { return false; } return true; }
if ($ret) { $id = mysqli_insert_id($link); } Response::Created($url . "/{$id}"); }); $app->delete($url, function () use($link) { $query = "DELETE FROM accounts"; $ret = mysqli_query($link, $query); if ($ret) { Response::Ok("Accounts are all successfully deleted."); } }); $app->delete($url . "/:accountID", function ($accountID) use($link) { $query = "DELETE FROM accounts WHERE accountID={$accountID}"; $ret = mysqli_query($link, $query); if ($ret) { Response::Ok("Account with ID {$accountID} was successfully deleted."); } }); $app->put($url, function () { Response::NotFound("Can't update all accounts simultaneously."); }); $app->put($url . "/:id", function ($accountID) use($link) { $query = "UPDATE accounts SET firstName='{$_POST["firstName"]}', lastName='{$_POST["lastName"]}' WHERE accountID={$accountID}"; $ret = mysqli_query($link, $query); $num_rows = mysqli_num_rows($ret); if ($num_rows <= 0) { Response::NotFound("Account with ID {$accountID} does not exists."); } echo $app->request->put("account"); });