1
如何選擇從現有字段計算出的自定義值?NOTORM自定義mysql函數
例如,我存儲了出生日期,並且我想選擇從mySql函數計算出來的年齡。
$app->get("https://stackoverflow.com/users/:id", function ($id) use ($app, $db) {
$user = $db->users()->where("users_id", $id);
if ($data = $user->fetch()) {
$hobbies = array();
foreach ($data->users_hobbies() as $hobbie) { // get all tags of $application
$hobbies[] = $hobbie["users_hobbies_name"]; // print the tag name
}
echo json_encode(array(
"id" => $data["users_id"],
"login" => $data["users_login"],
"mail" => $data["users_mail"],
"date_of_birth" => $data["users_date_of_birth"],
"age" => ??
"hobbies" => $hobbies
));
} else {
echo json_encode(array(
"status" => false,
"message" => "User ID $id does not exist"
));
}
});
你想在哪裏計算該值?在數據庫中還是在你的PHP代碼中? – Odi 2013-02-25 23:33:44
在數據庫中 – Klaitos 2013-02-27 08:59:19