Error Number: 1064
调用如下代码时发生Error Number: 1064,求高手解救!function get_exp_month_sub($year){
$where=array("exp_type_parent!="=>0);
$this->db->select("date_format('date','%c'),exp_type_sub_id");
$this->db->select_sum("price","total");
$this->db->where($where,NULL,FALSE);
$this->db->like("date",$year."-","after");
$this->db->from("expenses");
$this->db->join("expenses_type","expenses_type.exp_type_id=exp_type_sub_id");
$this->db->group_by("date_format(date,'%Y-%m-'),exp_type_sub_id");
$data=$this->db->get();
return $data;
}
错误信息: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 (`expenses`) JOIN `expenses_type` ON `exp_type_sub_id`=`expenses_type`.`exp' at line 2
SELECT date_format('date', `'%c')`, `exp_type_sub_id`, SUM(`price`) AS total FROM (`expenses`) JOIN `expenses_type` ON `exp_type_sub_id`=`expenses_type`.`exp_type_id` WHERE exp_type_parent!=0 AND ( `date` LIKE '2011-%') GROUP BY date_format(date, `'%Y-%m-')`, `exp_type_sub_id`
Filename: D:\xampp\htdocs\rico\system\database\DB_driver.php
Line Number: 330 没人会吗?求解啊---- 很明显,你的 SQL 写错了,你放到phpmyadmin 里一样无法执行。
建议你这么复杂的 SQL 不要用 Active Record,AR 复杂的 SQL 拼不出来。
在 phpmyadmin 调试好 SQL 以后,用 query() 方法直接执行即可。 有可能是数据库的不同导致的。我遇到这个情况是因为我要连接的 mssql但是我配置文件里却写的是mssql 所以导致出错说我是 mysql 有问题。你看看你连接数据库又没有出错就差不多了。如果是语句的问题,你完全可以把语句复制到phpmyadmin中执行以下。
页:
[1]