dragon202076 2017-12-19 14:55
浏览 29
已采纳

Zend Framework 2错误:在表网关中实现年份函数时无法执行语句

I have implemented tablegateway statements in my zf2 project but now I have problem when I used mysql year function couse I snipped it into greaterThanOrEqualTo function. this is my code

code:

$where = new Where();
$classYearMin = $classYear - 1;
$where->greaterThanOrEqualTo('year(date_a)', $classYear)
->and
->equalTo('id_type',1)
->and
->notEqualTo('semester_type','concat("B_","'.$classYearMin.'","/","'.$classYear.'")');
$sql= $this->tableGateway->select(function (Select $select) use ($where) {
    $select
    ->columns(array('semester_type'))
    ->order('date_a')
    ->where($where);
});

and my mysql output syntax :

Syntax:

select semester_type 
from skedul 
where year(date_a) >= 2010 
  and id_type = 1 
  and semester_type != concat('B_',2010-1,'/',2010) 
order by date_a;

and error output

Statement could not be executed (42S22 - 1054 - Unknown column 'year(date_a`)' in 'where clause')

Can anyone help me? Thanks in advance and sorry for my bad English

  • 写回答

1条回答 默认 最新

  • doudong2149 2017-12-19 15:12
    关注

    by default zend will assume that you are giving a column in greaterOrEqualTo. If you want to change that you need to use a Zend db expression.

    Change

    $where->greaterThanOrEqualTo('year(date_a)', $classYear)
    

    With

    $where->greaterThanOrEqualTo(new \Zend\Db\Sql\Expression('year(date_a)'), $classYear)
    

    By the way, you should print the real sql generated with ZF to find what does not work.

    Hope this will solve the issue

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 wamp3.3.5安装完成后图标正常显示绿色,鼠标左右键点击图标均无反应。求解决方法。
  • ¥15 鼠标点击的这条记录了什么?
  • ¥15 在写pid调速的程序时,电机始终维持最大速度
  • ¥15 帅锅们,我很想知道这个论坛是用什么模板搭的(T_T)
  • ¥15 请问如何查看手机root记录?
  • ¥15 商城小程序订单号重复
  • ¥15 学校优化算法sbo和蚁群算法怎么结合
  • ¥21 matlab怎么求时域信号的二阶导数
  • ¥15 判断两个表是否完全相同
  • ¥15 java map类型数据格式,如何快速通过前缀匹配元素