我在数据库中有两个值,例如
这是姓名
这是一个名字
我正在通过 SQL 查询搜索短语 th
SELECT * FROM [TABLE_NAME] WHERE title LIKE '%th%'
然后两个文件都显示了我只想显示 this is a name
部分的地方。我该如何进行。我已经尝试过 preg_merge 和其他部分,但它们没有用。有没有可以区分大小写
的SQL查询。或者我可以搜索确切术语的任何 php 方法。我的表格格式是 UTF8。不是拉丁将军。
最佳答案
SELECT * FROM tableName WHERE title COLLATE latin1_general_cs LIKE '%th%'
The default character set and collation are latin1 and latin1_swedish_ci, so nonbinary string comparisons are case insensitive by default. This means that if you search with col_name LIKE 'a%', you get all column values that start with A or a. To make this search case sensitive, make sure that one of the operands has a case sensitive or binary collation. For example, if you are comparing a column and a string that both have the latin1 character set, you can use the COLLATE operator to cause either operand to have the latin1_general_cs or latin1_bin collation:
更重要的是
If you want a column always to be treated in case-sensitive fashion, declare it with a case sensitive or binary collation. See Section 13.1.10, “CREATE TABLE Syntax”.
关于php - 按大写字母或小写字母搜索单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22060782/