views:

98

answers:

1

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 want to know If there is any way in Zend/SQL to handle this issue in query.

Thanks

+2  A: 

Try

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

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

Gordon
It is working. Thanks
NAVEED