Search code examples
mysqlsymfony-1.4doctrine-1.2dql

Question mark DQL is not considered?


I have the following DQL query:

$query = Doctrine_Query::create()
                ->select('p.genre')
                ->from('Profile p')
                ->where('sf_guard_user_id = ?',  11);

If I return the SQL syntax with $sql = $query->getSqlQuery(); I get:

SELECT p.id AS p__id, p.genre AS p__genre FROM profile p WHERE (p.sf_guard_user_id = ?)

This is not normal. It should be 11 not ?:

SELECT p.id AS p__id, p.genre AS p__genre FROM profile p WHERE (p.sf_guard_user_id = 11)

And if I write:

$query = Doctrine_Query::create()
                ->select('p.genre')
                ->from('Profile p')
                ->where('sf_guard_user_id = ' .  11);

The SQL syntax is correct.

Normally DQL should do this automatically. Why isn't happening ?


Solution

  • This is how prepared statement works. Values will be bound on database server Hence doctrine can not show the real values with the query.

    Doctrine will show a question mark if you use prepared statement not the real value.

    Checkout how it is describing here