I am using Zend_Db with the Pdo_Mysql driver. This quer开发者_Go百科y does not give any results:
$s = $db->prepare('SELECT ET.id
FROM elementTypes AS ET, language AS L1
WHERE L1.strId = ET.dispName AND L1.language = ?');
$s->execute(array(2));
pr($s->fetchAll());
If I hardcode the parameter, the expected rows are returned.
What is going on here?
Edit: Here's a stripped down script with even simpler queries: http://pastebin.com/84UtcGGZ
Eidt 2: I have drilled further down and found that the problem lies with PDO and comparing ENUMS with ints. See this question: PDO cannot compare mysql ENUM using integers in prepared statements If you know any fixes/workarounds on how to get this to work on Zend_Db, please post! :)**
The reason why the statement does not work is that L1.language is an ENUM, and you cannot compare ENUMS with integers in Zend_Db / PDO.
Why, and how to avoid this is explaied in this question: PDO cannot compare mysql ENUM using integers in prepared statements
精彩评论