mysql命令通过序列化数据吗? [英] mysql order by serialized data?

查看:132
本文介绍了mysql命令通过序列化数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要查询单个字段并按序列化数据对其进行排序,那有可能吗?

I need to query a single field and order it by serialized data, is that even possible?

我的表格字段是:

*********************************************
| meta_id | user_id | meta_key | meta_value |
*********************************************

我的查询看起来像这样

SELECT user_id FROM $wpdb->usermeta WHERE meta_key='ba_ur' 效果很好,但是在这里事情对我来说没有任何作用

SELECT user_id FROM $wpdb->usermeta WHERE meta_key='ba_ur' which works fine but here things start to make no scene to me

meta_value例如保存序列化数据 a:2:{s:4:"data";s:9:"text text";s:6:"number";s:2:"22";} 未序列化时会显示以下内容:

meta_value holds a serialized data for example a:2:{s:4:"data";s:9:"text text";s:6:"number";s:2:"22";} which when unserialized gives:

array (
  'data' => 'text text',
  'number' => '22',
)

而且我需要按序列化数据中的数字排序,所以回到我的问题,那是否有可能?如果可以的话,怎么办?

and i need to order by the number in that serialized data, so back to my question is that even possible? and if so then how?

谢谢.

推荐答案

否,这是不可能的.可接受序列化数据的唯一可能情况是,您不需要通过该数据进行搜索或排序.在所有其他情况下-将数据存储为单独的字段.

No, it is not possible. The only possible case when serialized data is acceptable is when you don't need to search or order by through that data. In all other cases - store your data as a separated fields.

这篇关于mysql命令通过序列化数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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