你好,我正在尝试在 doctrine codeigniter 中加入 3 个表,我已成功加入两个表,但在加入第三个表时遇到问题。
这是我的 codeigniter 事件记录查询。我想在 Doctrine 上处理这个查询
$query = $this->db->select('table1.name, table3.date')
->from('table1')
->join('table2', 'table2.id = table1.Uid')
->join('table3', 'table3.id = table1.Rid')
->where('table1.Uid', $Uid)
->get();
return $query->result();
这是我的 Doctrine 查询构建器查询,我在其中成功连接了两个表。
$qb = $this->em->createQueryBuilder();
$query = $qb->select('t1, t2')
->from('table1', 't1')
->join('table2', 't2')
// ->join('table3', 't3')
->where('t1.Uid = :Uid')
->andwhere('t2.Yid = :Yid')
->setParameters(array('Uid'=> $Uid, 'Yid' => $user_id))
->getQuery()
->getResult();
最佳答案
尝试使用下面的代码,似乎你的语法不正确。
$qb = $this->em->createQueryBuilder();
$query = $qb->select('t1.name', 't2.name')
->from('table1', 't1')
->leftJoin('t1', 'table2', 't2', 't2.id = t1.Uid')
->leftJoin('t1', 'table3', 't3', 't3.id = t1.Rid')
->where('t1.Uid = :Uid')
->andwhere('t2.Yid = :Yid')
->setParameters(array('Uid'=> $Uid, 'Yid' => $user_id))
->getQuery()
->getResult()
关于php - Codeigniter 和 doctrine 连接三个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32243413/