I am trying to use like in zend
switch($filter2)
{
case ‘name’:
switch($filter1)
{
case ‘start_with’:
$search = “\”pd_name like ?\”, ‘$patient_search_name%'”;
break;
case 'contains':
$search = "'pd_name like ?', '%$patient_search_name%'";
break;
case 'exact_match':
$search = "'pd_name = ?', $patient_search_name";
break;
}
break;
case 'phone':
switch($filter1)
{
case 'start_with':
$search = "'pd_phone like ?', '$patient_search_name%'";
break;
case 'contains':
$search = "'pd_phone like ?', '%$patient_search_name%'";
break;
case 'exact_match':
$search = "'pd_phone = ?', $patient_search_name";
break;
}
break;
}
$select = $this->getDbTable()->select()
->from("patient_data",
array('*'))
->where("$search");
but when i see the query log its like
SELECT `patient_data`.* FROM `patient_data` WHERE ("pd_name like ?", 'bhas%')
where as the ? should have been replaced by the value ….how to solve this??
That will not work. If you want the placeholder to be substituted you will need to pass in two parameters to
where(), e.g.:Otherwise, the single string you are passing will be used for the where clause as-is, so you would need to do something like:
That is to say, build the entire where clause as a single string. Alternatively, use the
selectobject within the switch statement, e.g.:Or just have two variables in each
case, e.g.: