douwan7382 2012-07-15 07:04
浏览 37
已采纳

在codeigniter中使用活动记录和学说

I was curious to know whether its ok if I user codeigniter's active record query besides using doctrine in some cases, simultaneously. Because in some cases, I find active record more easy and quick way to get things done then writing doctrine query. For example, consider the following case where I need to return total number of rows in a table, in doctrine:

$query = $this->em->createQueryBuilder()
  ->select("count(c)")
  ->from($this->entity, "c")
  ->getQuery();
return $query->getSingleScalarResult();

vs via active record:

return $this->db->count_all_results($this->table);

You can see how easy it is in active record. There may be more such cases. So, is there any pros or cons in using both?

Also, will they use two different db connection to perform their operations?

  • 写回答

3条回答 默认 最新

  • doutongwei4380 2012-07-17 00:12
    关注

    You can use both Doctrine and ActiveRecord at the same time. Swordfish has highlighted the some problems. In addition to that if you bring in new developer team, the learning curve will be more.

    I suggest choose one and stick with it. IMO, both are equally good. You should choose based on your current project and personal preference. You can find the very good comparison here

    What Does Doctrine Add Above Active Record - CodeIgniter?

    Regarding the two queries you mentioned, if you use DQL, it might look simple

    $query = $em->createQuery('SELECT COUNT(u.id) FROM Entities\User u');
    $count = $query->getSingleScalarResult();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器