assets
id unsigned int(P)
description varchar(200)
+----+-------------+
| id | description |
+----+-------------+
| 1 | Widget A |
| .. | ........... |
+----+-------------+
パスワードのハッシュについては、 PHP の crypt() 関数を参照してください。
customers
id unsigned int(P)
first_name varchar(50)
middle_name varchar(50) // Allow NULL
last_name varchar(50)
email varchar(255)
username varchar(32)
password varbinary(255) // hashed
...
+----+------------+-------------+-----------+----------------------------+-----------+----------+-----+
| id | first_name | middle_name | last_name | email | username | password | ... |
+----+------------+-------------+-----------+----------------------------+-----------+----------+-----+
| 1 | John | Quincy | Public | jqp@privacy.com | johnqball | xxxxxxxx | ... |
| 2 | Jane | NULL | Doe | ladyinred@chrisdeburgh.com | janeykins | xxxxxxxx | ... |
| .. | .......... | ........... | ......... | .......................... | ......... | ....... | ... |
+----+------------+-------------+-----------+----------------------------+-----------+----------+-----+
locations
id unsigned int(P)
description varchar(200)
+----+-------------+
| id | description |
+----+-------------+
| 1 | Facility A |
| 2 | Facility B |
| .. | ........... |
+----+-------------+
reservations
id unsigned int(P)
asset_id unsigned int(F assets.id)
customer_id unsigned int(F customers.id)
from_id unsigned int(F locations.id)
to_id unsigned int(F locations.id)
beg datetime
end datetime
+----+-------------+----------+---------+-------+---------------------+---------------------+
| id | customer_id | asset_id | from_id | to_id | beg | end |
+----+-------------+----------+---------+-------+---------------------+---------------------+
| 1 | 1 | 1 | 1 | 2 | 2013-09-13 03:00:00 | 2013-09-13 14:00:00 |
| 1 | 1 | 1 | 2 | 1 | 2013-09-14 19:00:00 | 2013-09-15 07:00:00 |
| 1 | 1 | 1 | 1 | 2 | 2013-09-15 10:00:00 | 2013-09-15 17:00:00 |
| 1 | 1 | 1 | 2 | 1 | 2013-09-16 08:00:00 | 2013-09-16 13:00:00 |
| 1 | 1 | 1 | 1 | 2 | 2013-09-17 10:00:00 | 2013-09-17 17:00:00 |
| .. | ........... | ........ | ....... | ..... | ................... | ................... |
+----+-------------+----------+---------+-------+---------------------+---------------------+
施設 A で現在利用できるものを確認するには:
SELECT DISTINCT asset_id, * FROM reservations
WHERE to_id = 1 AND
beg > NOW()
ORDER BY beg, end
施設 B で明日 15:00 に利用できるものを調べるには:
$target_datetime = '2013-09-14 15:00:00';
SELECT DISTINCT asset_id, * FROM reservations
WHERE to_id = 2 AND
beg > $target_datetime
ORDER BY beg, end