dongliechuich10319 2014-08-28 14:47
浏览 60
已采纳

getDbTable() - > select() - > where where(Zend Framework 1.x)

I've currently got a query I'm preparing in Zend 1.x. The select query is formed within a class as you'd expect:

I'm setting up the query as follows:

    // prepare query
    $this->getDbTable()->select()
        ->setIntegrityCheck(false)
        ->from(array('mdt' => 'meta_data_type'))
        ->where('id = :id')
        ->bind(
            array(
                ':id' => $id
            )
        );
    // report SQL for debugging
    echo $this->getDbTable()->select()->__toString();

As you can see, this isn't exactly the hardest query. However: the returned SQL is as follows:

SELECT `meta_data_type`.* FROM `meta_data_type`

Can anyone give me any gotchas on how to debug this? It seems correct to me. I've tried to follow the examples online, but given our system approach (sat inside a Mapper pattern, with non-standard table namings amongst other things) this isn't too much help.

FYI : The actual data it returns matches what you'd expect from a "get row" operation on a "complete data set".. as in: the first row is well formed. It's just not constrained by the where clause (as you'd expect with it missing from SQL!).

FYI 2 : The bind/where isn't the issue. If I change the whole ending to:

->where('id = 2');

It still does not show this inside the clause.

  • 写回答

1条回答 默认 最新

  • doutiao2540 2014-08-28 15:32
    关注

    Your query looks okay, although this isn't the syntax I used to use with ZF1. However, by calling $this->getDbTable()->select() a second time for the echo, you are outputting a fresh new query without any of your params.

    Simplest fix would be to assign it to a variable instead:

    // prepare query
    $select = $this->getDbTable()->select()
                   ->setIntegrityCheck(false)
                   ->from(array('mdt' => 'meta_data_type'))
                   ->where('id = :id')
                   ->bind(
                        array(
                            ':id' => $id
                        )
                    );
    
    // report SQL for debugging
    echo $select;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)