codeigniter与sql

时间:2012-10-18 12:10:25

标签: codeigniter

public function display( $date )
        {
            $this->db->select('*');         
            $this->db->from('event');
                 $this->db->where('start_date','$date');
                     $res = $this->db->get()->result_array();           
                 return $res;   
        }
     }

我在codeigniter中使用此代码从我的数据库中获取数据。但是我得到的错误是“在sql中从字符串转换日期和/或时间时转换失败”.anyone请帮助。

2 个答案:

答案 0 :(得分:0)

没有''分号的$ date变量:

public function display( $date ) { 
$this->db->select('*');
$this->db->from('event'); $this->db->where('start_date',$date); 
$res = $this->db->get()->result_array();
return $res;
} 

答案 1 :(得分:0)

public function display( $date )
        {
            $this->db->select('*');         
            $this->db->from('event');
                 $this->db->where('start_date',cast($date as date));
                     $res = $this->db->get()->result_array();           
                 return $res;   
        }
     }

应该使用正确的日期格式来投射$ date应该采用yyyy-mm-dd的格式,否则就像这样构建你发送日期的adate格式

$newdate=date_create($date);
$perfectdate=date_format($newdate,'Y-m-d');