LoginSignup
2
3

More than 5 years have passed since last update.

Doctrine NativeQuery 使い方メモ

Posted at

Doctrineで、データベースのバージョンなど、エンティティが不要なSQLを実行したいとき。

例:データベースのバージョンを取得する

select version();

のようなSQLの場合、以下のようなコードで実行できる

$rsm = new \Doctrine\ORM\Query\ResultSetMapping();
$rsm->addScalarResult('version', 'v');

$version = $app['orm.em']->createNativeQuery('select version()', $rsm)
                         ->getSingleScalarResult();
var_dump($version);
// PostgreSQL 8.4.20 on i386-redhat-lin....

参考
http://doctrine-orm.readthedocs.org/en/latest/reference/native-sql.html

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3