PHP SQL SELECT where like search item with multiple words

前端 未结 6 1881
暖寄归人
暖寄归人 2020-12-05 03:18

I have a select where like query for a seach form which is as follows:



        
6条回答
  •  伪装坚强ぢ
    2020-12-05 04:09

    I think that the best solution would be to use Regular Expressions. It's cleanest and probably the most effective. Regular Expressions are supported in all commonly used DB engines.

    In MySQL there is RLIKE operator so your query would be something like:

    SELECT * FROM buckets WHERE bucketname RLIKE "(?=.*apple)(?=.*and)(?=.*pear)"
    

    Did't tested it, hope that my expression is right for MySQL regexp "dialect".

    More on MySql regexp support:
    http://dev.mysql.com/doc/refman/5.1/en/regexp.html#operator_regexp

提交回复
热议问题