title: MySQL User defined variable within Doctrine and Symfony
body: <p>I have the following Doctrine statement which works fine.</p>
  
  <pre><code>$query = $this-&gt;createQuery('r')
              -&gt;select('u.id, CONCAT(u.first_name, " ", LEFT(u.last_name,1)) as full_name, u.first_name, u.last_name, u.gender, r.run_time')
              -&gt;innerJoin('r.ChallengeUser u')
              -&gt;orderBy('run_time')
              -&gt;execute(array(), Doctrine::HYDRATE_ARRAY_SHALLOW);
  </code></pre>
  
  <p>I need to add a row count into this. Now I know with raw SQL you can do this;</p>
  
  <pre><code>SET @rank=0;
  SELECT @rank:=@rank+1 as rank, u.id, u.first_name ....etc
  </code></pre>
  
  <p>So my question is, how can I get this to run with Symfony 1.4 and Doctrine?
  I am using MySQL for this project.</p>
  
  <hr>
  
  <p>Edit...
  I figured it out..</p>
  
  <pre><code>Doctrine_Manager::getInstance()-&gt;getCurrentConnection()-&gt;standaloneQuery('SET @rank=0;')-&gt;execute();
  
  $query = $this-&gt;createQuery('r')
              -&gt;select('r.run_time, @rank:=@rank+1 rank, r.user_id, CONCAT(u.first_name, " ", LEFT(u.last_name,1)) as full_name, u.first_name, u.last_name, u.gender')
              -&gt;leftJoin('r.ChallengeUser u')
              -&gt;orderBy('run_time')
              -&gt;execute(array(), Doctrine::HYDRATE_ARRAY_SHALLOW);
  </code></pre>
  
  <p>Add the standalone query in to set the variable, and swap the inner join to a left join.</p>