【问题标题】:Zend select data with where concatZend 使用 where concat 选择数据
【发布时间】:2017-03-29 09:59:27
【问题描述】:

谁能帮我解决这个问题?

我想在设置年份和月份时获取数据。 当我尝试使用where concat 年份和月份选择数据时遇到问题。 当我在我的数据库上尝试时,那个 sql 查询正在运行,但在 Zend 中我得到了错误:

$db = Zend_Registry::get('db');

$select = $db->select()
            ->from(array('air'=>$this->_name), 
                array('sumtotal' => new Zend_Db_Expr('SUM(air.price) + SUM(inst.cicilan)')));
$select->joinLeft(array('s' => 'store'), 's.id = air.store_id');
$select->joinLeft(array('ar' => 'area'), 'ar.name = s.regional');
$select->joinLeft(array('inst' => 'installment'), 'inst.sn = air.sn');
$select->where('(air.status = ?', A);
$select->orwhere('air.status = ?', B);
$select->orwhere('air.status = ?', C);
$select->orwhere('air.status = ?', D);
$select->orwhere('air.status = ?', E);
$select->orwhere('air.status = ?', F);
$select->orwhere('air.status = ?', G);
$select->orwhere('air.status = ?', H);
$select->orwhere('air.status = ?', I);
$select->orwhere('air.status = ?', J);
$select->orwhere('air.status = ?)', K);
$select->where('ar.id = ?', $area);
$select->where('CONCAT(YEAR(air.date)-MONTH(air.date)) = ?', $year . '-' . $month );
$data = $db->fetchOne($select);
return $data;

【问题讨论】:

  • 你遇到了什么错误?
  • 没有错误报告。但我没有得到现有数据的价值。我得到了“NULL”。 @thebluefox
  • 我认为语法缺失: $select->where('CONCAT(YEAR(air.date)-MONTH(air.date)) = ?', $year . '-' . $月 );因为当我刚写的时候: $select->where('MONTH(air.date) = ?', $month );那工作.....

标签: php sql zend-framework


【解决方案1】:

您可能需要将 concat 包装到 new Zend_Db_Expr( 中,除非代码将查找名为 CONCAT(YEAR(air.date)-MONTH(air.date)) 的 db 列。

另外,如果你想在年份和月份之间加上一个破折号,那就是CONCAT( YEAR(air.date), '-', MONTH(air.date) )(看到参数之间的逗号了吗?)。

最后是 ZF1,所以你可以通过die($select->assemble()); 来帮助调试。

【讨论】:

    猜你喜欢
    • 2013-11-12
    • 1970-01-01
    • 2020-10-24
    • 1970-01-01
    • 2013-07-11
    • 1970-01-01
    • 1970-01-01
    • 2013-08-22
    • 1970-01-01
    相关资源
    最近更新 更多