如题:连接sql 2005数据库,使用视图模型
- <?php
- namespace Index\Model;
- use Think\Model\ViewModel;
- class CommentaViewModel extends ViewModel{
- public $viewFields=array(
- 'comment'=>array('gid','comment','pic','time'=>'cctime','status'=>'cstatus','_as'=>'aa'),
- 'guest'=>array('avatar','username','_as'=>'bb','_on'=>'aa.gid=bb.id'),
- );
- }
- ?>
复制代码
代码中使用order排序就会报错,不使用排序则正常,
- $comment=$Model->where($where)->limit($limit)->order('cctime')->select();
复制代码
------报错:ERR: SQLSTATE[42000]: [Microsoft][SQL Server Native Client 10.0][SQL Server]无法绑定由多个部分组成的标识符 "aa.time"。
- $comment=$Model->where($where)->limit($limit)->select();
复制代码
----正常
研究这个问题研究很久了。最终找到解决办法。把->order('cctime') 这个改成:->order('thinkphp.cctime') 问题解决。
我的语句是这样的:$order=D('OrderView'); $orderinfo=$order->field('cusid')->order('thinkphp.cusid desc')->where($map)->limit($firstrow,$listRows)->select();
只是不知道什么原理,有懂的大神请解释下