存储在MySQL的阵列? [英] Storing arrays in MySQL?

查看:267
本文介绍了存储在MySQL的阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Facebook的页面FQL它显示的FQL表结构,这里是低于截图显示它的一些(截图消失)。

On the Facebook FQL pages it shows the FQL table structure, here is a screenshot below to show some of it (screenshot gone).

您会发现,有些项目是一个数组,如meeting_sex,meeting_for CURRENT_LOCATION。我只是好奇,你认为他们正在存储本作中的MySQL数组或只是回到它为一体,从这个数据真的让我觉得这是作为数组保存。如果你认为它是,如果你已经做过类似的,什么是存储这些项目作为一个数组1表中的字段,然后检索它作为一个PHP页面上的一个阵列的好方法?

You will notice that some items are an array, such as meeting_sex, meeting_for current_location. I am just curious, do you think they are storing this as an array in mysql or just returning it as one, from this data it really makes me think it is stored as an array. IF you think it is, or if you have done similar, what is a good way to store these items as an array into 1 table field and then retrieve it as an array on a PHP page?

推荐答案

有用于存储作为数组两个选项:

There are two options for storing as an array:

第一,其中你提到的,就是让一个或几个,表格,并列举要存储的每个可能的密钥。这是最好的用于搜索和具有数据是很有意义的。

The first, which you mentioned, is to make one, or several, tables, and enumerate each possible key you intend to store. This is the best for searching and having data that makes sense.

不过,对于你想做的事,使用 连载( ) 。注意:不要永远永远永远尝试在其本地字符串形式来搜索针对此数据。这是更快(更理智和)只是重新加载它,请致电 反序列化() ,然后搜索您的标准,而不是制定一些疯狂的搜索模式,听从你的命令。

However, for what you want to do, use serialize(). Note: DO NOT EVER EVER EVER try to search against this data in its native string form. It is much faster (and saner) to just reload it, call unserialize(), and then search for your criteria than to develop some crazy search pattern to do your bidding.

编辑:如果是我,这是什么,我认真制定供他人使用(或甚至为自己使用,要完全诚实的),我可能会创建第二个查找表来所有的按键存储为列;哎呀,如果你这样做, mysql_fetch_assoc()可以给你你只是通过运行一个快速的第二个查询想要的阵列(或者你可以通过<$ C $提取出来C> JOIN 编辑查询)。但是,如果这只是快速和肮脏得到任何完成任务,然后序列化阵列可能适合你。除非你真的,真的不在乎以往搜索的数据,正确的列到关键的关系,我想大多数人都同意,更胜一筹。

If it were me, and this were something I was seriously developing for others to use (or even for myself to use, to be completely honest), I would probably create a second lookup table to store all the keys as columns; Heck, if you did that, mysql_fetch_assoc() could give you the array you wanted just by running a quick second query (or you could extract them out via a JOINed query). However, if this is just quick-and-dirty to get whatever job done, then a serialized array may be for you. Unless you really, really don't care about ever searching that data, the proper column-to-key relationship is, I think most would agree, superior.

这篇关于存储在MySQL的阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆