开发者

Zend: How to fetch record from Database without considering case sensitive?

开发者 https://www.devze.com 2022-12-19 04:30 出处:网络
I am using Zend Framework. I want to fetch record from database without considering case sensitive. This is my Person Table:

I am using Zend Framework. I want to fetch record from database without considering case sensitive.

This is my Person Table:

Id|Name  |Gender|Occupation
-----------------------------------
1 |Naveed|Male  |Software Engineer
-----------------------------------
2 |Ali   |Male  |Software Developer

Now If I use the following strings to search for a record in above table using 'Occupation' in where clause, it should always return record number 1 (Naveed's Record).

Software Engineer
software engineer
SoFtwarE EngIneeR
SOFTWARE ENGINEER

I am using following way to fetch records from database in Zend.

$occupation = "Software Engineer";
$table = new Model_Person_DbTable();
$select = $table->select();
$select->where( 'Occupation = ?', $occupation ); 
$rows = $table->fetchAll( $select );

Now how to change above zend code for my scenario ?

I can create a logic to ignore case sensitive outside database query but I w开发者_如何学Cant to know If there is any way in Zend/SQL to handle this issue in query.

Thanks


Try

$select->where( 'upper(Occupation) = upper(?)', $occupation ); 

This will make the values in the column and the search value uppercase

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号