php - Codeigniter 和 doctrine 连接三个表

标签 php mysql codeigniter doctrine-orm doctrine

你好,我正在尝试在 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()

关于 Constructing a new QueryBuilder object 的更多信息

关于php - Codeigniter 和 doctrine 连接三个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32243413/

相关文章:

php mysql bootstrap行按钮/div高度

mysql - 连接两个表时计算总销售额而不丢失值

php - 使用全名搜索,而不仅仅是名字或姓氏

mysql - SQL - 排序依据 "Custom Preference List"

css - 提交表单时图像消失

php - 如何使用html按钮发送POST请求

php - 使用 css 和 php 格式化 html 页面输出

php - 正确处理 php 中转义的 unicode 字符

php - 使用 SQLSrv 和 PHP 5.4.7 连接到 MSSQL 时出错

php - 在 Heredoc 中格式化数组值