Doctrine Why this query return 0 rows?
I have the following DQL query:
$q = Doctrine_Query::create()
->select('id')
->from('Comment')
->where("active='?' AND object_id='?' AND group_name = '?'"
, array(1, 1, 'unit'));
Which produce the 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 = '?' AN开发者_如何学CD c.group_name = '?')
bindings: 1, 1, unit
In database table:
id user_id object_id group_name name active
1 0 1 unit test 1
When I execute de query it returns 0 rows. Why?
If I go in phpmyadmin
and I run
SELECT * FROM comment WHERE active=1 AND object_id=1 AND group_name='unit'
the result contains the record I look for.
In phpmyadmin the query generated by Doctrine identify the table name as 'c'. This is very strange, since I used in my application other DQL querys like this one and works.
Thanks.
Remove quotes around parameter placeholders:
where("active=? AND object_id=? AND group_name = ?"
or use named parameters
:
where("active= :ative AND object_id= :object_id AND group_name = :group_name"
, array(':ative'=>1, ':objet_id'=>1, 'group_name'=>'unit')"
精彩评论