1.7X升级到2.0出现的故障
本帖最后由 snllll 于 2011-2-13 00:03 编辑升级后出现如下问题:
1、原来在model中操作时,无所谓多一个还是少一个from,我也就一直没注意过,现在发现不行了。
比如:
$this->db->select('title,createdate,id');
$this->db->from('news');
$query = $this->db->get('news',10);
以前这样写是没问题的,但是现在会报错。必须将$this->db->from('news');这一句去掉。
2、where语句大面积出现问题。
我以前又少部分是sql语法,如手册中提到的:
$where = "name='Joe' AND status='boss' OR status='active'";
$this->db->where($where);
我写的是:
$sql = " cid>0";
$this->db->where($where);
报错:
A Database Error Occurred
Error Number: 1064
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 '0 ORDER BY `id` desc LIMIT 15' at line 3
SELECT * FROM (`news`) WHERE `cid>` 0 ORDER BY `id` desc LIMIT 15
Filename: XXXXXX\system\database\DB_driver.php
Line Number: 330
我尝试了多种方法改写,均失败。
尝试过的方法:
$this->db->where('cid>',0);
同样的错误
接着来,以下这两句的效果一样的:
$this->db->where('cid','>0');
$this->db->where(array('cid'=>'>0'));
加了一句echo $this->db->last_query(); 得到:
SELECT * FROM (`news`) WHERE `cid` = '>0' ORDER BY `id` desc LIMIT 15
$this->db->where(array('cid>'=>0));
A Database Error Occurred
Error Number: 1064
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 '0 ORDER BY `id` desc LIMIT 15' at line 3
SELECT * FROM (`news`) WHERE `cid>` 0 ORDER BY `id` desc LIMIT 15
Filename: ***\system\database\DB_driver.php
Line Number: 330
我们手册是不是还没更新呢?
http://codeigniter.org.cn/user_guide/database/active_record.html 官方也说明了可以带运算符的,但是这里为什么不可以呢!?
本事不行,恳请指点一二,多谢多谢 PHP Version 5.2.11
Apache VersionApache/2.2.13 (Win32) PHP/5.2.11
SystemWindows NT THINKPAD 5.1 build 2600
Build DateSep 16 2009 19:39:11
Server APIApache 2.0 Handler
Virtual Directory Supportenabled :dizzy:很伤心!升级计划暂时搁置 手册已经更新了。
你的问题还需要检查下,是不是 CI BUG。 回复 6# Hex
今天我尝试升级还是这个问题!
难道别的朋友没有遇到吗? 回复 7# snllll
重新下载一份 CI 2.0 试试?然后在新版本上写个 AR 测试? 本帖最后由 jeongee 于 2011-2-14 09:21 编辑
回复 3# snllll
请使用空格啊,就是字段名和运算符之间要有个空格,要不然就会连同运算符算作字段名的,当然也就出错了。 年后回来,看到ci升级到2.0了,给力啊!
页:
[1]
2