1

I use the cakePHP framework I have a question about how models handle MySQL query connections. Basically I have a model which I need to set recursive level of 2, to get to some information in a deeper model. Although I have removed all binding of level 2 models which I do not need the framework is still executing a large number of queries to build the result set.

What I want to know is if the framework opens and closes a MySQL connection for every query or does it open a single connection and executes all the queries and then close the connection?

Thanks

Gabriel Spiteri
  • 4,896
  • 12
  • 43
  • 58

2 Answers2

0

It seems to me that CakePHP connect to the database and then executes all queries. Look here for the code: https://github.com/cakephp/cakephp/blob/master/lib/Cake/Model/Datasource/Database/Mysql.php

FrediWeber
  • 1,099
  • 1
  • 10
  • 21
0

You can always unbind model associations and bind them on the fly or build your entire mega query on the fly by using 'joins' syntax. Take a look at this question to see an example and at this page from the cookbook. I was able to reduce the number of queries from tens to one by correctly joining tables.

Community
  • 1
  • 1
bancer
  • 7,475
  • 7
  • 39
  • 58