title: Error with a query - Doctrine2/Symfony2
body: <p>I'm trying to execute a simple query, but I can't understand where is my mistake. Please help!</p>
  
  <p>This is in the repository class:</p>
  
  <pre><code>public function searchFriends ($param)
      {
           return $this-&gt;getEntityManager()
              -&gt;createQuery('SELECT f FROM EMMyFriendsBundle:Friend f WHERE f.name='.$param)
              -&gt;getResult();
      }
  </code></pre>
  
  <p>And this is how I call it from the controller's action:</p>
  
  <pre><code> $em = $this-&gt;getDoctrine()-&gt;getEntityManager();
   $result = $em-&gt;getRepository('EMMyFriendsBundle:Friend')
                -&gt;searchFriends($search-&gt;getWords()); 
  </code></pre>
  
  <p>When it's in this way, I get the following error:</p>
  
  <pre><code>[Semantical Error] line 0, col 54 near 'Maria': Error: 'Maria' is not defined.
  500 Internal Server Error - QueryException
  </code></pre>
  
  <p>I tried to put the searched value in quotes in this way:</p>
  
  <pre><code>public function searchFriends ($param)
      {
           return $this-&gt;getEntityManager()
              -&gt;createQuery('SELECT f FROM EMMyFriendsBundle:Friend f WHERE f.name=" '.$param ' " ')
              -&gt;getResult();
      }
  </code></pre>
  
  <p>but then I get</p>
  
  <pre><code>[Syntax Error] line 0, col 59: Error: Expected end of string, got ' " '
  500 Internal Server Error - QueryException
  </code></pre>
  
  <p>Could you please tell me how to write the query correctly? Thanks in advance!</p>
  
  <hr>
  
  <p><strong>EDIT</strong></p>
  
  <p>I also tried this:</p>
  
  <pre><code>public function searchFriends ($param)
  {
       $q = $this
          -&gt;createQueryBuilder('f')
          -&gt;where('f.name = :name')
          -&gt;setParameter('name', $param)
          -&gt;getQuery();
  
       return $q-&gt;getResult();
  }
  </code></pre>
  
  <p>with this:</p>
  
  <pre><code> $em = $this-&gt;getDoctrine()-&gt;getEntityManager();
   $result = $em-&gt;getRepository('EMMyFriendsBundle:Friend')
                -&gt;searchFriends($search-&gt;getWords());
  </code></pre>
  
  <p>and it's workiiing </p>