• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Database Switching to Test Environment.

I have database config file like this:

$active_group = "development";
$active_record = TRUE;

/************* Development Environment **************/
$db['development']['hostname'] = "localhost";
$db['development']['username'] = "root";
$db['development']['database'] = "project_development";

/************* Test Environment **************/
$db['test']['hostname'] = "localhost";
$db['test']['username'] = "root";
$db['test']['database'] = "project_test";

Then I have a Controller "Unit_test" to do all test specific. I have add following code to make a database switching:

// use Test database environment
    echo $this->db->last_query();

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
echo $this->user->db->last_query();
to see if that brings back the right sql

[quote author="Evil Wizard" date="1247672786"]try this
echo $this->user->db->last_query();
to see if that brings back the right sql[/quote]

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

You could load the profiler, that should print all the used queries in generating a page. It has issues on PHP 4 though.



Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.