3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

EC-CUBE3でDoctrine/DBALを使う

Posted at

EC-CUBE3では、データベースの操作は通常、Doctrin/ORMというO/Rマッパーを使っています。
O/Rマッパーは便利ですが、複雑な集計を行うときなど、SQLを直接書きたい場面もあると思います。

そんな時はDoctrine/DBALを使うとSQLでデータを取ってくることができます。

こんな感じ。PDOと同じような使い方です。

$stmt = $app['db']->query('select * from dtb_product');
while ($row = $stmt->fetch()) {
    dump($row);
}

クエリビルダを使ってSQLを構築することもできます。

$qb = $app['db']->createQueryBuilder();
$stmt = $qb
    ->select('*')
    ->from('dtb_product')
    ->where('name = :name')
    ->setParameter('name', 'パーコレーター')
    ->execute();

while ($row = $stmt->fetch()) {
    dump($row);
}

参考
http://www.doctrine-project.org/projects/dbal.html

3
5
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
3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?