我正在使用 CodeIgniter 并进行了这样的查询。
$this->db->select("first_name as 'First Name', last_name as 'Last Name', phone as 'Phone', os.group as 'Group', gender as 'Gender', birth_date as 'DOB', email as 'Email', street_address as 'Address', city as 'City', province as 'Province', postal_code as 'Postal Code', country 'Country', payment_amount as 'Payment Amount', DATE_FORMAT(payment_date, '%d/%m/%Y') as 'Payment Date', an.notes as 'Notes'");
$this->db->join('athlete_notes an', 'os.id = an.id', 'inner');
$this->db->group_by(array("first_name", "last_name"));
$this->db->order_by("last_name asc, first_name asc");
$query = $this->db->get('offline_shoppers os');
并得到这个 csv 输出:
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=members_list.csv");
header("Pragma: no-cache");
header("Expires: 0");
echo $this->dbutil->csv_from_result($query);
我正在尝试将 payment_date 格式化为 d/m/Y 但 DATE_FORMAT 给了我错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM (`offline_shoppers` os) INNER JOIN `athlete_notes` an ON `os`.`id` = `an`.`' at line 2
我能做些什么来解决这个问题?