开发者

zend like mysql problem

开发者 https://www.devze.com 2022-12-29 00:14 出处:网络
I am trying to use like in zend switch($filter2) { case \'name\': switch($filter1) { case \'start_with\': $search = \"\\\"pd_namelike ?\\\", \'$patient_search_name%\'\";

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);
0

精彩评论

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