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