mysql select query within a serialized array

前端 未结 14 1311
忘了有多久
忘了有多久 2020-11-29 07:51

I\'m storing a list of items in a serialized array within a field in my database (I\'m using PHP/MySQL).

I want to have a query that will select all the records that

14条回答
  •  一向
    一向 (楼主)
    2020-11-29 08:10

    Working with php serialized data is obviously quite ugly, but I've got this one liner mix of MySQL functions that help to sort that out:

    select REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(searchColumn, 'fieldNameToExtract', -1), ';', 2), ':', -1), '"', '') AS extractedFieldName
    from tableName as t 
    having extractedFieldName = 'expressionFilter';
    

    Hope this can help!

提交回复
热议问题