0

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?

j0k
  • 22,600
  • 28
  • 79
  • 90
Rana
  • 5,912
  • 12
  • 58
  • 91

3 Answers3

1

I was curious to know whether its ok if I user codeigniter's active record query besides using doctrine in some cases, simultaneously

Yes it is ok. There's no rule against it.

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

Depends on how you use them. Connection pooling in PHP is not how it is in other languages. You might have to write a custom class to hook them both up to use a common connection, but its not something that id spend my time for if im in an hurry.

Regarding Pros and Cons

It is good to stick with active record as far as codeigniter is concerned as it is cleaner, efficient and comes as part of codeigniter and provide you almost everything that you might need. You can get the extended active record class from codeigniter forums that extends on the base class to provide some complex join functionality as well.

But technically its not an issue using two layers, other than the fact that it gets messy, and makes two separate connections.

swordfish
  • 4,899
  • 5
  • 33
  • 61
1

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();
Community
  • 1
  • 1
venkat
  • 2,310
  • 1
  • 15
  • 15
0

Find the link for the doctrine integration in CI https://github.com/mitul69/codeigniter-doctrine-integration

I will update more document in couple of days.

Mitul
  • 3,431
  • 2
  • 22
  • 35