php - 按大写字母或小写字母搜索单词

标签 php mysql sql

我在数据库中有两个值,例如

  1. 这是姓名
  2. 这是一个名字

我正在通过 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%'

Reference

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/

相关文章:

php - 获取组/线程/主题的 N 行

php - Google 总是返回错误的验证 ID token

php - 自动将 Excel 导入 phpmyadmin

php - MySQL:如果值存在则对该行进行更新,如果值不存在则进行插入

php - 可以存在在 php 上加载动态类的最佳实践/方法吗?

PHP 不返回变量

mysql 查询返回两个结果而不是一个

javascript - 试图调查页面加载性能错误 : What is "Scripting" and "Idle"?

sql - 为什么索引查找会在统计数据中显示高扫描计数?

c# sql插入有很多参数