5

我目前正在使用 symfony 和 DBAL 从外部数据库收集数据。

        $conn = $this->get('database_connection');

        $users = $conn->fetchAll('SELECT * FROM cms_clients');

        print_r($users);

上面的代码工作正常,但我需要做更复杂的查询,我能找到的唯一文档是http://doctrine-dbal.readthedocs.org/en/latest/reference/query-builder.html

文档非常好,但我不确定如何在我的示例中实现下面的代码。

$queryBuilder ->select('u.id', 'u.name') ->from('users', 'u') ->where('u.email = ?') ->setParameter(0, $userInputEmail) ;

解决方案,无论如何感谢重播

      $conn = $this->get('database_connection');
        $parms = array($DataSource, 'STORE');

        $query = "SELECT * FROM cms_things LEFT JOIN cms_stores ON cms_things.id=cms_stores.thing_id WHERE client_id = ? AND type = ? ";

        $users = $conn->fetchAll($query, $parms);
4

1 回答 1

3

像这样的事情可能会有所帮助

$qb = $em->createQueryBuilder();
$params = array('state' => 'active');
$qb->select("DISTINCT (a.id) as url , a.name , a.pages , a.section , a.clickable")
        ->from('Tbl', 'a')
        ->leftJoin('a.country', 'cnt')
        ->where('a.state=:state')
        ->setMaxResults($limit);
$qb->setParameters($params);
$query = $qb->getQuery();
$list = $query->getArrayResult();
于 2014-03-12T10:10:58.003 回答