php - Syntax for MySQL REGEXP CONCAT -


i'm trying make pdo prepared statement using regexp concat function. in phpmyadmin can run following query returns proper results database contents (the 'city' value (denver, in case)) bound parameter, i'm putting in there explicitly development):

select `user_id` `id`  `usermeta`  (`meta_key` = 'custom_field') , (`meta_value` regexp '.*"leagues";.*s:[0-9]+:"a".*') , (`meta_value` regexp '.*"city";.*s:[0-9]+:"denver".*') 

however, if try use concat function on last line, result empty set. in other words, mysql isn't throwing errors on query itself, correct data isn't being selected:

select `user_id` `id`  `usermeta`  (`meta_key` = 'custom_field') , (`meta_value` regexp '.*"leagues";.*s:[0-9]+:"a".*') , (`meta_value` regexp concat('\'.*"city";.*s:[0-9]+:"', 'denver', '".*\'')) 

i've tried escaping colon, semicolon , period characters no luck. appreciated.

you adding literal quotes expression:

and (`meta_value` regexp concat('\'.*"city";.*s:[0-9]+:"', 'denver', '".*\''))                                       ^                                       ^ 

those aren't in first expression. quotes in first expression encapsulating sql string. so:

and (`meta_value` regexp concat('.*"city";.*s:[0-9]+:"', 'denver', '".*')) 

i think work. don't need use mysql concat. concatenate variable expression in binding. make sql:

select `user_id` `id`  `usermeta`  (`meta_key` = 'custom_field') , (`meta_value` regexp '.*"leagues";.*s:[0-9]+:"a".*') , (`meta_value` regexp ?) 

then build binding like:

'.*"city";.*s:[0-9]+:"' . $city . '".*' 

the leading , trailing .* not necessary. rule match without because aren't using anchors.


Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -