我正在尝试在 MySQL 中实现某些目标,但即使在这里或其他站点上有所有答案,我仍然无法实现目标。
我有两张表,一对多的关系。
TABLE Files
COLUMNS id, title, description, uploaded, size, extension, etc.
TABLE Files_Meta
COLUMNS id, parent_id, key, value
显然,每个文件都有多个元数据,表示为Files_Meta表中的多行。例如File1有 meta Author、Place、Time、Tags、Camera——如果它是一张照片。
我正在尝试从Files表中选择所有行,包括元数据。
标准结果
stdClass Object
(
[id] => 10
[title] => Hello world
[size] => 745198
[extension] => jpg
[user_id] => 0
[category_id] => 0
[date_uploaded] => 2012-06-08 13:37:55
[description] =>
[downloaded] => 0
[viewed] => 8
)
stdClass Object
(
[id] => 90
[parent_id] => 10
[key] => place
[value] => New York
)
我想要的是
stdClass Object
(
[id] => 10
[title] => Hello world
[size] => 745198
[extension] => jpg
[user_id] => 0
[category_id] => 0
[date_uploaded] => 2012-06-08 13:37:55
[description] =>
[downloaded] => 0
[viewed] => 8
[meta] => Array (
place => New York
author => John Doe
time => March 2001
camera => Canon EOS
etc.
)
)
是否有可能在 MySQL 中实现这一点?不必看起来像这样,没有那个数组。
stdClass Object
(
[id] => 10
.
.
[place] => New York
[author] => John Doe
[time] => March 2001
[camera] => Canon EOS
)
提前感谢您的回复或提示。