序列化数组中的mysql选择查询 [英] mysql select query within a serialized array

查看:1664
本文介绍了序列化数组中的mysql选择查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我存储在一个领域内的序列化阵列的项目清单在我的数据库(我使用PHP / MySQL的)。

I'm storing a list of items in a serialized array within a field in my database (I'm using PHP/MySQL).

我想有一个查询,将选取所有包含这些项目是在阵列中的特定一个的记录。

I want to have a query that will select all the records that contain a specific one of these items that is in the array.

事情是这样的:

select * from table WHERE (an item in my array) = '$n'

希望这是有道理的。

Hopefully that makes sense.

任何意见将大大AP preciated。

Any ideas would be greatly appreciated.

感谢

推荐答案

所以你的意思是使用MySQL在已系列化用的序列命令并存储在数据库字段?我的第一反应是:OMG。我的第二反应是:为什么?在明智的事可以是:

So you mean to use MySQL to search in a PHP array that has been serialized with the serialize command and stored in a database field? My first reaction would be: OMG. My second reaction would be: why? The sensible thing to do is either:


  1. 检索数组到PHP,反序列化,并在其
  2. 搜索
  3. 忘记存储MySQL作为序列数据,并存储为常规表和索引它快速搜索

我会选择第二个选项,但我不知道你的背景。

I would choose the second option, but I don't know your context.

当然,如果你真的想,你可以尝试用 SUBSTRING 或另一个MySQL功能的东西,并试图操纵的领域,但我没有看到为什么你会想要。这是繁琐的,而且这将是一个不必要的丑陋的黑客。在另一方面,这是一个谜,而这里的人们往往喜欢拼图,这样的如果你真的想的然后发布字段的内容,我们可以给它一个镜头。

Of course, if you'd really want to, you could try something with SUBSTRING or another MySQL function and try to manipulate the field, but I don't see why you'd want to. It's cumbersome, and it would be an unnecessary ugly hack. On the other hand, it's a puzzle, and people here tend to like puzzles, so if you really want to then post the contents of your field and we can give it a shot.

这篇关于序列化数组中的mysql选择查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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