【问题标题】:Doctrine EM -> getting data from 2 entitiesDoctrine EM -> 从 2 个实体获取数据
【发布时间】:2014-01-06 15:36:34
【问题描述】:

我有一张桌子:sms_followers。我有 2 个实体:俱乐部和用户。我知道如何将数据插入表中,但我无法从中获取数据。谁能给我一些支持?

我想检查带有俱乐部 ID 的用户 ID 是否已经存在。

到目前为止我的代码:

$club = $this->em->getRepository('Club')->findBy(array('id' => $clubid));
$user = $this->em->getRepository('User')->findOneBy(array('id' => $this->auth->getUser()->getId()));

$notifiction = $user->getSmsfollower();

这样看:

$sql = 'SELECT userid, clubid FROM sms_followers WHERE clubid=value AND userid=value';

echo $row['clubid'];
echo $row['userid'];

【问题讨论】:

    标签: php symfony doctrine-orm


    【解决方案1】:

    建议:使用 Doctrine DBAL,您可以创建如下查询:

    $stmt = $this->getDoctrine()->getEntityManager()
                ->getConnection()
                ->prepare('SELECT userid, clubid FROM sms_followers WHERE clubid=? AND userid=?');
    $stmt->bindValue(1, $userid);
    $stmt->bindValue(2, $clubid);
    $stmt->execute();
    $data = $stmt->fetchAll();
    

    documentation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多