Database Switching to Test Environment. |
[eluser]heha[/eluser]
I have database config file like this: Code: $active_group = "development"; Then I have a Controller "Unit_test" to do all test specific. I have add following code to make a database switching: Code: // use Test database environment It looks OK except for one thing, last_query() function. It print "SELECT * FROM user" instead of "SELECT * FROM user JOIN user_type ON user.id = user_type.user_id" which is in "User_model" class. I must copy and paste "echo $this->db->last_query();" to inside function "get_by_id" to get the correct result. It looks like "$this->db" that I called in controller wasn't the same "$this->db" that I called in model anymore. Maybe it cause some problem because "unset($this->db);" line but I cannot omit this line out since it won't load the test database config to override development database config. What should I do?
[eluser]Evil Wizard[/eluser]
try this Code: echo $this->user->db->last_query();
[eluser]heha[/eluser]
[quote author="Evil Wizard" date="1247672786"]try this Code: echo $this->user->db->last_query(); Yes, it brought me the right sql. Then what should I do? Do I need to call "$this->user->db->last_query()" in all line that I want?
[eluser]Evil Wizard[/eluser]
It means that the instance of the db is not the same as the instance in the user model
[eluser]Maglok[/eluser]
You could load the profiler, that should print all the used queries in generating a page. It has issues on PHP 4 though. http://ellislab.com/codeigniter/user-gui...iling.html Code: $this->output->enable_profiler(TRUE); |
Welcome Guest, Not a member yet? Register Sign In |