如何在PHP CodeIgniter中将日期作为参数传递给MySQL存储过程?

我正在尝试在我的Web应用程序中创建日期范围过滤.为此,我使用日期选择器进行输入,并将其传递给控制器​​进行建模.当我回显它时,它将为我提供从日期选择器中选择的正确日期值.但是,当我运行我的代码时,它给了我空白的输出.我想知道我的代码有什么问题.

这是我的SP代码:

DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `testDefects`(IN `startdate` DATE, IN `enddate` DATE)
    NO SQL
    DETERMINISTIC
BEGIN
SELECT `defect_id`, `user_id`, `defect_rooms`, `defect_start_date`, `defect_subject`, `defect_responsibility`, `defect_time_frame`, `defect_followup_date`, `defect_assign_to`, `defect_notes`, `defect_details`, `defect_status`, `defect_updated_date` FROM `tbl_defects` WHERE defect_followup_date BETWEEN startdate AND enddate;
END$$
DELIMITER ;

这是我的控制器代码:

public function DefectFilterTest()
    {
        # code...
        $user = $this->ion_auth->user()->row();
        $data['username'] = $user->username;

        $data['user_id'] = $user->id;
        $user_id = $user->id;
        $data['groupId'] = $this->l->groupId($user_id);
        $data['group'] = $data['groupId']['0']->group_id;
        $data['title'] = 'Property Defects List';

        $startdate = $this->input->post('fromdate');
        $enddate = $this->input->post('todate');

        if($startdate == ''){
            $startdate ='1900-01-01';
        }
        if($enddate == ''){
            $enddate ='2100-01-01';
        }
        echo $startdate. "<br>";
        echo $enddate. "<br>";

        $data['defectslist'] = $this->p->testDefects($startdate, $enddate);

        echo "<pre>";
        print_r($data['defectslist']);
        echo "</pre>";
        exit();

        $this->load->view('template/header', $data); 
        $this->load->view('Property/defectList', $data); 
        $this->load->view('template/footer'); 
    }

这是我的模型代码:

public function testDefects($startdate, $enddate)
    {
        # code...   testDefects
        $query = $this->db->query("call testDefects($startdate, $enddate)");

        if ($query->num_rows()) {
            $data = $query->result();
            $query->next_result(); 
            $query->free_result();
            return $data;
        }else{
            return false;
        }
    }

我已经用谷歌搜索出来了,但是我被困住了,欢迎任何帮助,谢谢.

最佳答案
尝试这个:

# code...   testDefects
$query = $this->db->query("call testDefects('$startdate', '$enddate')");

转载注明原文:如何在PHP CodeIgniter中将日期作为参数传递给MySQL存储过程? - 代码日志