[英]Get row from mysql using specific value with regexp ( json string )
I'm storing permissions into DB with Array JSON String, and i want select them by permission specific permission. 我正在使用数组JSON字符串将权限存储到数据库中,我想通过权限特定的权限来选择它们。 at this time I'm selecting them like this:
目前,我正在这样选择他们:
1 | Dog | [3,4]
2 | Cat | [33,4]
3 | Tiger | [5,33,4]
4 | wolf | [3,5]
SELECT * FROM `pages` WHERE access REGEXP '([^"])3([^"])'
it works but not as it should work. 它有效,但不起作用。 This query gives me all records which contains 3 but also it gives which contains 33. my question is how i must format my regexp to get row by specific value into json string.
该查询为我提供了包含3的所有记录,但也给出了包含33的所有记录。我的问题是我必须如何格式化我的regexp才能按特定值将行获取到json字符串中。
ps i have mysql 5.5 so as i know on this version json functions is not supported ps我有mysql 5.5,所以我知道这个版本不支持json函数
如果字段中仅包含数字,则可以将正则表达式更改为仅在要查找的字符串(此处为“ 3”)没有紧邻其的其他数字的情况下采用值:
SELECT * FROM `pages` WHERE access REGEXP '([^"0-9])3([^"0-9])'
REGEXP '[[:<:]]3[[:>:]]'
也就是说,使用“单词边界”东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.