开发者

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.


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');


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);


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';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜