Welcome Guest, Not a member yet? Register   Sign In
Database Switching to Test Environment.
#1

[eluser]heha[/eluser]
I have database config file like this:

Code:
$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:

Code:
// use Test database environment
    unset($this->db);
    $this->load->database('test');
    $this->db->get('user');
    $this->load->model('user');
    $this->user->get_by_id(1);
    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?


Messages In This Thread
Database Switching to Test Environment. - by El Forum - 07-15-2009, 02:27 AM
Database Switching to Test Environment. - by El Forum - 07-15-2009, 04:46 AM
Database Switching to Test Environment. - by El Forum - 07-15-2009, 04:59 AM
Database Switching to Test Environment. - by El Forum - 07-15-2009, 05:12 AM
Database Switching to Test Environment. - by El Forum - 07-15-2009, 05:12 AM



Theme © iAndrew 2016 - Forum software by © MyBB