php - 如何在选择数据的任何序列化字段的数组键上添加 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 子句。请给我建议。
谢谢
解决方案
也许这行应该是这样的,你省略了反斜杠来转义双引号,并且放错了 REGEXP 关键字:
$this->db->where("ValueDetails REGEXP",".*\"Employer\";s:[0-9]+:\"jack\".*");
推荐阅读
- ios - 如何在 Xcode 模拟器中关闭 iPhone X?
- html - 使用 htaccess 重定向网站时出错
- c - 在 C 中关闭文件描述符(或套接字)
- ionic-framework - 如何使用cordova-plugin-local-notification在离子的特定时间每天获取本地通知
- amazon-s3 - 现有存储桶的 Cloudformation 触发事件
- javascript - 脚本返回长度不一致的字符串
- sonarcloud - SonarCloud 的 GitHub PR 分析
- reactjs - 在获取用户令牌之前触发 React Router Protected Routes
- facebook - 无法通过 Graph API 访问 facebook 群组
- javascript - 如何创建动态ajax函数?