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
Search for value within BLOB column in MySQL
提问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 TEXT
field.
无论如何,如果可能,最好使用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%"';