zoukankan      html  css  js  c++  java
  • symfony中,使用原声的sql语句

     1 /**
     2 * 数组形式的原生sql
     3 */
     4 public function arrayA(array $did)
     5 {
     6 $statement = $this->getEntityManager()->getConnection()->executeQuery('
     7     SELECT did, count(1) as num
     8     FROM position_structure
     9     WHERE did in (?)
    10     AND status = 1
    11     GROUP BY did
    12     ', array($did), array(Connection::PARAM_INT_ARRAY));
    13     return $statement->fetchAll();
    14 }
    15  
    16 /**
    17 * 单个值的原生sql
    18 */
    19 public function fetchCompaniesByUserId($userId){
    20     $statement = $this->getEntityManager()->getConnection()->prepare('
    21     SELECT c.id,c.name,c.type FROM company_admin ca
    22     LEFT JOIN company c ON c.id = ca.company_id
    23     WHERE ca.user_id = :userId');
    24     $statement->bindValue('userId', $userId);
    25     $statement->execute();
    26     return $statement->fetchAll();
    27 }    
  • 相关阅读:
    2019.8.8 python day03
    2019.8.7 python进阶day02
    2019.8.6(python day01)
    2019.8.5
    2019.8.2
    2019.8.1
    2019.7.31
    2019.7.30
    面向对象进阶
    访问可见性问题和@property装饰器
  • 原文地址:https://www.cnblogs.com/spectrelb/p/6795013.html
Copyright © 2011-2022 走看看