title: Symfony 3- select query
body: <p>I'm new to symfony and I'm having a hard time developing a query ... thanks if anyone could help me</p>
  
  <p>What I need is
  select id and code from table where id = userid and code = usercode</p>
  
  <p>if the values ​​are equal if statement to insert data into the database, otherwise error message</p>
  
  <p>i try this</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code> $teste = $this-&gt;getDoctrine()-&gt;getRepository('AppBundle:Codigo');
          $query = $teste-&gt;createQueryBuilder('p')
            -&gt;where('p.codigo = :codigo')
            -&gt;andWhere('p.utilizadorID = :user')
            -&gt;setParameter('codigo', $codigo)
            -&gt;setParameter('user', $user)
            -&gt;getQuery();
          }
      $cod = $query-&gt;getResult();
  
    if ( $cod &lt;&gt; NULL) {
    $link = $data['linkpodcast'];
    
    $podcast-&gt;setUrl($link);  
    $podcast-&gt;setIdUser($user);
    $sn = $this-&gt;getDoctrine()-&gt;getManager();      
    $sn -&gt; persist($podcast);
      
    $sn -&gt; flush();
              
    $this-&gt;addFlash(
      'notice',
      'Podcast Adicionado'
    );
    return $this-&gt;redirectToRoute('gravar_list');
  }</code></pre>
  </div>
  </div>
  </p>