简体   繁体   English

Select mysql 和 php 用于将邮件发送到序列化数组

[英]Select mysql with php for mail into serialize array

With an input of info@test.com how can I select a record in the database with the below value?输入info@test.com我怎样才能在数据库中 select 记录具有以下值?

a:4:{s:4:"nome";s:14:"Napoleon";s:5:"email";s:23:"info@test.com";s:19:"conferma_condizioni";s:1:"1";s:2:"ip";s:12:"84.33.92.109";}

I have tried:我努力了:

$sql_mail = "SELECT * FROM wp_cf7db WHERE data REGEXP '.*'info@test.com';s:[0-9]+:'2'.*'"

The object is compiled with the data type, in your case a string, and the length of the string. object 使用数据类型(在您的情况下为字符串)和字符串的长度进行编译。 You could use something like:你可以使用类似的东西:

'select * 
from table 
where data REGEXP concat("s:",' . mb_strlen($email) . ', ":", ?, ";")'

then bind the $email , that should get you pretty close.然后绑定$email ,这应该让你非常接近。 If an email contains special regex characters though you'll need to escape those.如果 email 包含特殊的正则表达式字符,但您需要转义这些字符。 Alternatively a like could be used.或者,可以使用like的。 Wildcards would only then need to be escaped:只有这样,通配符才需要转义:

'select * 
from table 
where data like concat("%s:",' . mb_strlen($email) . ', ":", ?, ";%")'

Your previous attempt also probably could have worked but you needed to fix the quoting:您之前的尝试也可能有效,但您需要修复引用:

'.*'info@test.com';s:[0-9]+:'2'.*'

the single quotes are for the regexp encapsulation, additionally the object construction uses double quotes, so you'd want:单引号用于正则表达式封装,另外 object 构造使用双引号,所以你想要:

'.*"info@test.com";s:[0-9]+:"2".*'

If s:5:"email";s: is always preceding you also could add that to make it a bit stricter.如果s:5:"email";s:总是在前面,您也可以添加它以使其更严格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM