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

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.

我目前在Zend 1.x中准备了一个查询。 选择查询是在 你期望的一个类: p>

我按如下方式设置查询: p>

  //准备查询
 $  this-> getDbTable() - > select()
  - > setIntegrityCheck(false)
  - > from(array('mdt'=>'meta_data_type'))
  - > where('  id =:id')
  - > bind(
 array(
':id'=> $ id 
)
); 
 //报告用于调试的SQL 
 echo $ this-&gt  ; getDbTable() - > select() - > __ toString(); 
  code>  pre> 
 
 

正如您所看到的,这不是最难的查询。 但是:返回的SQL如下: p>

  SELECT`meta_data_type`。* FROM`meta_data_type` 
  code>  pre> 
 
 

任何人都可以给我任何关于如何调试此问题的问题? 这对我来说似乎是正确的。 我尝试在线跟踪这些示例,但是考虑到我们的系统方法(坐在Mapper模式中,其中包括非标准表命名),这不是太多帮助。 p> FYI:它返回的实际数据与您对“完整数据集”的“获取行”操作的期望值相匹配,如下所示:第一行格式正确。 它不受where子句的约束(正如你所期望的那样,它从SQL中缺失!)。 p>

FYI 2:bind / where不是问题。 如果我将整个结尾更改为: p>

   - > where('id = 2'); 
  code>  pre> 
 
 

它仍然没有在条款中显示这一点。 p> div>

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;