在这里,我尝试使用此代码将日期放入数据库中,但无法正常工作
$app->put('/finance/[{studentid}]', function ($request, $response, $args) {
$input = $request->getParsedBody();
$sql = "UPDATE feepaid SET amount =:amount, refNumber =:refNumber, datePaid =: datePaid
WHERE studentid =:studentid";
$sth = $this->db->prepare($sql);
$sth->bindParam("studentid", $args['studentid']);
$sth->bindParam("amount", $input['amount']);
$sth->bindParam("refNumber", $input['refNumber']);
$sth->bindParam("datePaid", $input['datePaid']);
$sth->execute();
return $response->withJson($input, 200)->withStatus(200)->withHeader('Content-type', 'application/json');
});
});
我在数据库中的date属性是日期类型,我正在使用angular来获取要发送到后端的日期。我该如何运作?
答案 0 :(得分:0)
这是工作的
$app->put('/finance/[{studentid}]', function ($request, $response, $args) {
$date = (new DateTime($input['datePaid']))->format('Y-m-d H:i:s');
$input = $request->getParsedBody();
$sql = "UPDATE feepaid SET amount =:amount, refNumber =:refNumber, datePaid =:datePaid WHERE studentid =:studentid";
$date = (new DateTime($input['datePaid']))->format('Y-m-d H:i:s');
$sth = $this->db->prepare($sql);
$sth->bindParam("studentid", $args['studentid']);
$sth->bindParam("amount", $input['amount']);
$sth->bindParam("refNumber", $input['refNumber']);
$sth->bindParam("datePaid", $date);
$sth->execute();
return $response->withJson($input, 200)->withStatus(200)->withHeader('Content-type', 'application/json');
});