我正在使用 Zend 框架。我想在不区分大小写的情况下从数据库中获取记录。
这是我的人员表:
Id|Name |Gender|Occupation
-----------------------------------
1 |Naveed|Male |Software Engineer
-----------------------------------
2 |Ali |Male |Software Developer
现在,如果我使用以下字符串在 where 子句中使用“职业”来搜索上表中的记录,它应该始终返回记录编号 1(Naveed 的记录)。
Software Engineer
software engineer
SoFtwarE EngIneeR
SOFTWARE ENGINEER
我在 Zend 中使用以下方式从数据库中获取记录。
$occupation = "Software Engineer";
$table = new Model_Person_DbTable();
$select = $table->select();
$select->where( 'Occupation = ?', $occupation );
$rows = $table->fetchAll( $select );
现在如何为我的场景更改上面的 zend 代码?
我可以创建一个逻辑来忽略区分大小写的外部数据库查询,但我想知道 Zend/SQL 中是否有任何方法来处理查询中的这个问题。
谢谢
最佳答案
尝试
$select->where( 'upper(Occupation) = upper(?)', $occupation );
这将使列中的值和搜索值大写
关于php - 发送 : How to fetch record from Database without considering case sensitive?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2190362/