Reputation: 800
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.
Upvotes: 1
Views: 779
Reputation: 33148
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;
Upvotes: 2