首页 > 解决方案 > 如何在选择数据的任何序列化字段的数组键上添加 where 子句?

问题描述

我在序列化数组字段的键上添加了 where 子句(我使用的是 PHP/MySQL)。
但 SQL 不工作并显示错误。

显示错误是: "Parse error: syntax error, unexpected ''Employer'' (T_CONSTANT_ENCAPSED_STRING) in...."

序列化数组是:(保存在数据库表中) a:2:{s:8:"Employer";s:9:"sanjayEMP";s:7:"Section";s:10:"production";}

我的 CodeIgniter SQL 是:

   $this->db->select("*");
   $this->db->select("emplyee_details");
   $this->db->where("status",1);
   $this->db->where("ValueDetails","REGEXP '.*"Employer";s:[0-9]+:"jack".*'");
   $this->db->get()->result_array();

这里,
ValueDetails是数据库表中序列化数组的一个字段。
Employer是数据库表中序列化字段的数组键。

如果有人知道如何在任何专业领域的数组键上添加 where 子句。请给我建议。

谢谢

标签: php

解决方案


也许这行应该是这样的,你省略了反斜杠来转义双引号,并且放错了 REGEXP 关键字:

$this->db->where("ValueDetails REGEXP",".*\"Employer\";s:[0-9]+:\"jack\".*");

推荐阅读