我需要将SQL本机放在查询Builder Doctrine2中 [英] I need to put SQL native in query Builder Doctrine2
本文介绍了我需要将SQL本机放在查询Builder Doctrine2中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在查询构建器教条2中使用SQL NATIVE来使用SQL函数(CONCAT,REPLACE,LDAP)。请帮助我。
i need to work with SQL NATIVE in query Builder doctrine 2 for using SQL Function (CONCAT,REPLACE,LDAP) . please Help me.
推荐答案
您可以尝试:
$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
}
如果要对服务执行此类请求,可能需要:
If you want to do such a request on a service, you may need :
use Doctrine\DBAL\Connection;
这篇关于我需要将SQL本机放在查询Builder Doctrine2中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文