So this is odd and hopefully there is a simple answer. I have a SQL query that used a date as the first parameter in a where() clause. But for some reason CodeIginter appears to be trying to add in extra escape characters,
Here is my code
$this->db->select("*");
$this->db->from("equip_reserve");
$this->db->where('equip_list_id = '.$equip_list_id);
$this->db->where('"'. date("Y-m-d H:i",strtotime($startdate)) .'" between date and returndate');
Here is the result:
SELECT * FROM 'equip_reserve' WHERE 'equip_list_id' = 5 AND "2016-02-29 '14:20'" between 'date' and 'returndate'
As you can see the date after the AND clause is causing this statement to fail.
Any suggestions on how to fix it?
I ended up fixing it by just passing the SQL directly to CodeIgniter instead of using their helper functions. In case anyone ever has this problem.
$st = date("Y-m-d H:i",strtotime($startdate));
$sql = "SELECT * FROM `equip_reserve` WHERE ? between `date` AND `returndate` and `equip_list_id` = ?";
$query = $this->db->query(
$sql,
array($star,$equip_list_id)
);
return $query->result();
Fixed!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.