用户
 找回密码
 入住 CI 中国社区
搜索
查看: 5909|回复: 14
收起左侧

[HELP] 1.7X升级到2.0出现的故障

[复制链接]
发表于 2011-2-13 00:01:58 | 显示全部楼层 |阅读模式
本帖最后由 snllll 于 2011-2-13 00:03 编辑

升级后出现如下问题:
1、原来在model中操作时,无所谓多一个还是少一个from,我也就一直没注意过,现在发现不行了。
比如:
PHP复制代码
 
$this->db->select('title,createdate,id');
$this->db->from('news');
$query = $this->db->get('news',10);
 
复制代码

以前这样写是没问题的,但是现在会报错。必须将$this->db->from('news');这一句去掉。

2、where语句大面积出现问题。
我以前又少部分是sql语法,如手册中提到的:
PHP复制代码
 
[font=Verdana]$where = "name='Joe' AND status='boss' OR status='active'";
$this->db->where($where);[/font]
[font=Verdana]
复制代码

我写的是:
PHP复制代码
 
[font=Verdana]$sql = " cid>0"; [/font]
[font=Verdana]$this->db->where($where);[/font]
[font=Verdana]
复制代码

报错:
HTML复制代码
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


复制代码


我尝试了多种方法改写,均失败。
尝试过的方法:
PHP复制代码
 
[font=Verdana]$this->db->where('cid>',0);[/font]
[font=Verdana]
复制代码

同样的错误

接着来,以下这两句的效果一样的:
PHP复制代码
 
[font=Verdana]$this->db->where('cid','>0');[/font]
[font=Verdana]$this->db->where(array('cid'=>'>0'));[/font]
[font=Verdana]
复制代码

加了一句echo $this->db->last_query(); 得到:
SQL复制代码
 
SELECT * FROM (`news`) WHERE `cid` = '>0' ORDER BY `id` DESC LIMIT 15
 
复制代码


PHP复制代码
 $this->db->where(array('cid>'=>0));
复制代码
HTML复制代码
 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
 
 
 
复制代码
 楼主| 发表于 2011-2-13 00:04:16 | 显示全部楼层
 楼主| 发表于 2011-2-13 00:06:00 | 显示全部楼层
官方也说明了可以带运算符的,但是这里为什么不可以呢!?   


本事不行,恳请指点一二,多谢多谢
 楼主| 发表于 2011-2-13 00:28:40 | 显示全部楼层
PHP Version 5.2.11
Apache Version  Apache/2.2.13 (Win32) PHP/5.2.11  
System  Windows NT THINKPAD 5.1 build 2600  
Build Date  Sep 16 2009 19:39:11  
Server API  Apache 2.0 Handler  
Virtual Directory Support  enabled
 楼主| 发表于 2011-2-13 00:30:44 | 显示全部楼层
  很伤心!升级计划暂时搁置
发表于 2011-2-13 03:23:32 | 显示全部楼层
手册已经更新了。
你的问题还需要检查下,是不是 CI BUG。
 楼主| 发表于 2011-2-14 00:20:56 | 显示全部楼层
回复 6# Hex


    今天我尝试升级还是这个问题!

难道别的朋友没有遇到吗?
发表于 2011-2-14 03:19:59 | 显示全部楼层
回复 7# snllll


    重新下载一份 CI 2.0 试试?然后在新版本上写个 AR 测试?
发表于 2011-2-14 09:20:35 | 显示全部楼层
本帖最后由 jeongee 于 2011-2-14 09:21 编辑

回复 3# snllll


   请使用空格啊,就是字段名和运算符之间要有个空格,要不然就会连同运算符算作字段名的,当然也就出错了。
发表于 2011-2-14 09:32:29 | 显示全部楼层
年后回来,看到ci升级到2.0了,给力啊!

本版积分规则