Php 如何在Kohana 3.1中使用备用DB连接
如果出现故障,请从Kohana 3.1控制器运行以下代码位Php 如何在Kohana 3.1中使用备用DB连接,php,kohana,kohana-3,kohana-db,Php,Kohana,Kohana 3,Kohana Db,如果出现故障,请从Kohana 3.1控制器运行以下代码位 $query = DB::select("select * from foo"); $results = $query->execute(); foreach($results as $result) { var_dump($result); } Kohana将尝试使用application/config/database.php返回的数组中的信息连接到数据库。具体而言,if将使用默认组中的信息集 return arra
$query = DB::select("select * from foo");
$results = $query->execute();
foreach($results as $result)
{
var_dump($result);
}
Kohana将尝试使用application/config/database.php
返回的数组中的信息连接到数据库。具体而言,if将使用默认组中的信息集
return array
(
'default' => array
(
'type' => 'mysql',
'connection' => array(
/**
* The following options are available for MySQL:
*
* string hostname server hostname, or socket
* string database database name
* string username database username
* string password database password
* boolean persistent use persistent connections?
*
* Ports and sockets may be appended to the hostname.
*/
'hostname' => 'localhost',
'database' => 'kohana',
'username' => FALSE,
'password' => FALSE,
'persistent' => FALSE,
但是,这个配置数组接受多个顶级项(我认为称为db组)。我如何/应该告诉Kohona 3.1使用非默认db组中设置的信息进行连接和查询。您可以将数据库组作为
execute
查看源代码:和
您还可以编写一个以$query=Database::instance('group')开头的查询。
$this->execute('group');