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.:
->where('pd_phone = ?', $patient_search_name);
Otherwise, the single string you are passing will be used for the where clause as-is, so you would need to do something like:
$search = "pd_phone = " . $patient_search_name;
That is to say, build the entire where clause as a single string. Alternatively, use the select
object within the switch statement, e.g.:
case 'exact_match': $select->where('pd_name = ?', $patient_search_name);
break;
Or just have two variables in each case
, e.g.:
$placeholder = "pd_phone = ?";
$value = '%' . $patient_search_name . '%';
break;
...
->where($placeholder, $value);
精彩评论