Symfony 3-选择查询

时间:2018-02-16 15:57:37

标签: symfony

我是symfony的新手,我很难开发查询...感谢有人能帮助我

我需要的是什么 从表中选择id和代码,其中id = userid,code = usercode

如果值相等,则if语句将数据插入数据库,否则出现错误消息

我试试这个



 $teste = $this->getDoctrine()->getRepository('AppBundle:Codigo');
        $query = $teste->createQueryBuilder('p')
          ->where('p.codigo = :codigo')
          ->andWhere('p.utilizadorID = :user')
          ->setParameter('codigo', $codigo)
          ->setParameter('user', $user)
          ->getQuery();
        }
    $cod = $query->getResult();

  if ( $cod <> NULL) {
  $link = $data['linkpodcast'];
  
  $podcast->setUrl($link);  
  $podcast->setIdUser($user);
  $sn = $this->getDoctrine()->getManager();      
  $sn -> persist($podcast);
    
  $sn -> flush();
            
  $this->addFlash(
    'notice',
    'Podcast Adicionado'
  );
  return $this->redirectToRoute('gravar_list');
}
&#13;
&#13;
&#13;

0 个答案:

没有答案