mikelbring
mikelbring

Reputation: 1492

Ko3: Change Database Config with Model Params

For some reason when I call a model I cannot use a different database config name besides default.

$carrier = new Model_Carrier('as400');

This is just goes back to the "default" config. Even if I rename or delete the default config, it still tries to go to it. I do have a "as400" config in my database.php file. If I set that as400 as my default it works, but I need other models to use the default which is MySQL. the as400 is NOT mysql. It's a ODBC driver I wrote.

Upvotes: 0

Views: 762

Answers (3)

Drekey
Drekey

Reputation: 1

For anyone still looking at this problem from an ORM model; the variable for a diferente DB configuration its $_db_group

So you would have

$_db_group = 'as400';

Upvotes: 0

dusan
dusan

Reputation: 9273

From Kohana documentation:

For each model, you can define which database configuration ORM will run queries on. If you override the $_db variable in your model, ORM will connect to that database.

In your case, in your models you can have this:

protected $_db = 'as400';

Edit Try using this instead:

$carrier = Model::factory('carrier', 'as400');

Upvotes: 1

mikelbring
mikelbring

Reputation: 1492

When I ran the query, I had to do put the database config name in the execute parameter. I don't understand why it won't go by the database I defined already in the query.

$result = DB::query(Database::SELECT, $sql)
              ->param(':search', strtoupper($search).'%')
              ->as_object()
              ->execute($this->_db);

Upvotes: 0

Related Questions