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条)

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计