views:

26

answers:

2

I am using Zend_Db with the Pdo_Mysql driver. This query 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: http://stackoverflow.com/questions/3625569/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! :)**

A: 

I hate to seem so dry but how about trying it the way it's documented?

http://framework.zend.com/manual/en/zend.db.statement.html

Rob Olmos
Have a look at this: http://pastebin.com/E1gg8TcB . Three attempts, none of which gives any results :(
Joernsn
+1  A: 

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: http://stackoverflow.com/questions/3625569/pdo-cannot-compare-mysql-enum-using-integers-in-prepared-statements

Joernsn