php 在 MySQL 的 BLOB 列中搜索值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3746756/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 10:57:32  来源:igfitidea点击:

Search for value within BLOB column in MySQL

phpmysqlsearchblob

提问by D3VELOPER

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

如何在 MySQL 的 Blob 列中搜索某些值?这可能吗?

回答by Zilverdistel

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

您应该能够像其他文本字段一样搜索 blob:

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 TEXTfield.

无论如何,如果可能,最好使用TEXT字段。

回答by Naveen Saroye

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.

如果你想让它同时适用于大写、小写或混合......在应用到 mysql 查询之前将搜索字符串设为小写,并LOWER()在查询中使用mysql 函数。确保为 mysql 转义字符串。

$search_text = strtolower($search_text);

$query = 'SELECT * 
FROM tablename 
WHERE LOWER( blob_field_name ) LIKE "%$search_text%"';