i need to work with SQL NATIVE in query Builder doctrine 2 for using SQL Function (CONCAT,REPLACE,LDAP) . please Help me.
问问题
7347 次
2 回答
3
您可以尝试:
$connection = $this->get('doctrine')->getConnection();
$toto = "toto";
$foo = "foo";
$params = array('param1' => $toto, 'param2' => $foo);
$request = "SELECT * FROM table WHERE param1 = :param1 AND param2 = :param2";
try {
$stmt = $connection->executeQuery($request, $params);
} catch (\PDOException $e) {
// echo $e->getMessage();
}
while (($result = $stmt->fetch(\PDO::FETCH_ASSOC))) {
// stuff with $result
}
如果您想对服务提出这样的请求,您可能需要:
use Doctrine\DBAL\Connection;
于 2012-09-15T10:05:50.820 回答
0
假设您有一个实体管理器存储在$this->em
:
$dql = $this->em->createQuery('
SELECT CONCAT(tbl.col1, ' ', tbl.col2), COALESCE(SUM(tbl.col3), 0)
FROM myTable tbl
');
$result = $dql->getResult();
print_r($result);
这是针对 Doctrine 2 ORM 的。该表myTable
可以通过包、类路径+类名或命名空间+类名(... FROM My\Namespace\Class\Model tbl ...
)来寻址。
于 2012-11-07T14:21:27.860 回答