1

I have an application which analyzes facebook user likes and shows him/her a video based on that data. Now the question is that I need to store the user like data in MYSQL table. the data looks approximately like this

array(2) { ["data"]=> array(46) { [0]=> array(4) { ["category"]=> string(21) "Media/news/publishing" ["name"]=> string(20) "Cosmopolitan Armenia" ["id"]=> string(15) "146307748762264" ["created_time"]=> string(24) "2013-03-20T14:40:43+0000" } [1]=> array(4) { ["category"]=> string(17) "Telecommunication" ["name"]=> string(5) "Zangi" ["id"]=> string(15) "386291674718829" ["created_time"]=> string(24) "2013-03-20T11:07:46+0000" } [2]=> array(4) { ["category"]=> string(13) "Musician/band" ["name"]=> string(11) "Ray Charles" ["id"]=> string(12) "430894850091" ["created_time"]=> string(24) "2013-03-16T22:03:46+0000" } [3]=> array(4) { ["category"]=> string(4) "Cars" ["name"]=> string(13) "Mazda Armenia" ["id"]=> string(15) "447042531989769" ["created_time"]=> string(24) "2013-03-16T22:01:46+0000" } [4]=> array(4) { ["category"]=> string(13) "Musician/band" ["name"]=> string(16) "Lockport Artists" ["id"]=> string(15) "615416628475063" ["created_time"]=> string(24) "2013-03-16T21:07:22+0000" }

what structure could you recommend for keeping such a data. I could keep in one column as a long text but it will be very unprofessional and the response time will be very high.

4

3 回答 3

1

我的建议是让您创建一个适当的表并将每个值存储在一列中。为什么?一列中的值是序列化的,它们只是填充空间,如果您愿意,您无法创建适当的查询,将来您可能想要创建统计信息或使用这些数据来研究用户的行为或类似的东西。

所以一个简单的查询只是为了计算你有多少喜欢的类别“媒体/新闻/出版”,你将被迫使用 like 函数在序列化数据中找到你需要的东西。

没有比查询数据库更容易的了,将结果作为数组检索,然后使用 json_encode 进行序列化

于 2013-04-15T14:39:18.640 回答
1

假设您的数组名为 $likes。你可以做类似的事情

$likes_to_store = json_encode($likes);

然后,您希望将您的存储$likes_to_store在您的数据库中。

稍后,在检索信息以供使用时,您会这样做

$likes_to_analyze = json_decode($likes_from_db);

这是将数组存储在数据库中以供以后使用的一种干净且简单的方法,因为数组被序列化为字符串,占用少量空间。

于 2013-04-15T13:44:55.570 回答
0

facebook 图以 JSON 回复。

您可以将 JSON 作为序列化数组存储在 MySQL 中。

不过,我建议在您的应用程序中创建一个“Like”类,并从 Facebook JSON 响应中实例化和持久化“Like”。

于 2013-04-15T13:23:55.007 回答