Search for value within BLOB column in MySQL

2019-04-18 04:58发布

How can I search inside Blob column in MySQL for some values ? and Is that possible ?

2条回答
ゆ 、 Hurt°
2楼-- · 2019-04-18 05:36

You should be able to search blobs like other text fields:

SELECT * 
FROM tablename 
WHERE blob_field_name LIKE '%value%'

One thing to notice is that search will be case-sensitive!

Anyway, if possible, it's better to use a TEXT field.

查看更多
劳资没心,怎么记你
3楼-- · 2019-04-18 05:37

If you want to make it work for both uppercase, lowercase or mixed... Make the search string in lower case before applying in mysql query and use LOWER() mysql function in query. make sure to escape string for mysql.

$search_text = strtolower($search_text);

$query = 'SELECT * 
FROM tablename 
WHERE LOWER( blob_field_name ) LIKE "%$search_text%"';
查看更多
登录 后发表回答