Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Kohana 3.3数据库::实例(';名称';)不工作_Php_Kohana_Kohana 3.3 - Fatal编程技术网

Php Kohana 3.3数据库::实例(';名称';)不工作

Php Kohana 3.3数据库::实例(';名称';)不工作,php,kohana,kohana-3.3,Php,Kohana,Kohana 3.3,我对Kohana 3.3和使用不同的数据库配置存在问题。 我有一个config/database.php,其中包含“default”配置和“other”,如下所示: 但在控制器或模型中尝试使用时: Database::instance('other'); Kohana仍将使用“默认”配置。我做错了什么 谢谢 您需要将连接存储在变量中,否则将使用默认连接 如果要更改kohana当前使用的连接,请尝试以下操作: Database::$default = 'other'; 从这一行开始,您的

我对Kohana 3.3和使用不同的数据库配置存在问题。 我有一个config/database.php,其中包含“default”配置和“other”,如下所示:


但在控制器或模型中尝试使用时:

 Database::instance('other'); 
Kohana仍将使用“默认”配置。我做错了什么


谢谢

您需要将连接存储在变量中,否则将使用
默认连接


如果要更改kohana当前使用的连接,请尝试以下操作:

Database::$default = 'other';
从这一行开始,您的代码将使用“其他”连接,直到您使用相同的方式再次将其切换为“默认”

在以简单方式执行查询时,还可以使用另一个DB配置一次:

DB::...->execute('other');
或者,如果您先前存储了DB实例:

$other = Database::instance('other');
DB::...->execute($other);

由。。。我是指你的查询。

是的,我试过:$db=Database::instance('other');但是没有区别。Kohana仍然使用默认配置。完美答案。正是我需要的!非常感谢。
$other = Database::instance('other');
DB::...->execute($other);