Search inside serialize data with MYSQL

后端 未结 3 1520
感动是毒
感动是毒 2021-02-11 08:37

I\'d like to search inside serialized array, data look like :

a:7:{i:0;s:2:\"34\";i:1;s:1:\"0\";i:2;s:2:\"42\";i:3;s:2:\"33\";i:4;s:2:\"48\";i:5;s:2:\"62\";i:6;s:2

相关标签:
3条回答
  • 2021-02-11 09:11
    foreach  ($array as $item) $keys[]=md5(serialize($item));
    
    $sql="insert into table set col='".serialize($array)."', `keys`='".implode(' ',$keys)."'";
    

    ...

    $item=5;
    $key=md5(serialize($item))
    $sql="select id from table where MATCH (`keys`) AGAINST ('$key' IN BOOLEAN MODE)";
    

    ...

    field keys has FULLTEXT index

    0 讨论(0)
  • 2021-02-11 09:14

    You're building $id_serialize, but are using $serialize in the query string., so you're searching for ... LIKE '%%', most likely.

    0 讨论(0)
  • 2021-02-11 09:18

    Your query is formatted a little wrong. If you are trying to pass $id_serialize to your query, it needs to be formatted like this:

    $id_serialize = $id;
    $req = requette("SELECT id FROM table WHERE col LIKE '%" . $id_serialize . "%'");
    
    0 讨论(0)
提交回复
热议问题