我有以下DQL查询:
$q = Doctrine_Query::create()
->select('id')
->from('Comment')
->where("active='?' AND object_id='?' AND group_name = '?'"
, array(1, 1, 'unit'));
哪个产生sql:
SELECT c.id AS c__id, c.group_name AS c__group_name, c.name AS c__name,
c.email AS c__email
FROM comment c
WHERE (c.active = '?' AND c.object_id = '?' AND c.group_name = '?')
bindings: 1, 1, unit
在数据库表中:
id user_id object_id group_name name active
1 0 1 unit test 1
当我执行de query时,它返回0行。为什么呢?
如果我进入phpmyadmin
并运行
SELECT * FROM comment WHERE active=1 AND object_id=1 AND group_name='unit'
结果包含我要查找的记录。
在phpmyadmin中,Doctrine生成的查询将表名识别为“c”。这很奇怪,因为我在我的应用程序中使用了像这样的其他DQL查询并且可以工作。
感谢。
答案 0 :(得分:1)
删除参数占位符周围的引号:
where("active=? AND object_id=? AND group_name = ?"
或使用named parameters
:
where("active= :ative AND object_id= :object_id AND group_name = :group_name"
, array(':ative'=>1, ':objet_id'=>1, 'group_name'=>'unit')"