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 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能