Kohana的数据库配置

来源:互联网 发布:喜曼多鱼线淘宝旗舰店 编辑:程序博客网 时间:2024/05/22 23:12

1、在application/bootstrap.php 文件里找到Kohana::modules并打开database开关

Kohana::modules(array( //'auth'       => MODPATH.'auth',       // Basic authentication// 'cache'      => MODPATH.'cache',      // Caching with multiple backends// 'codebench'  => MODPATH.'codebench',  // Benchmarking tool 'database'   => MODPATH.'database',   // Database access// 'image'      => MODPATH.'image',      // Image manipulation// 'minion'     => MODPATH.'minion',     // CLI Tasks// 'orm'        => MODPATH.'orm',        // Object Relationship Mapping// 'unittest'   => MODPATH.'unittest',   // Unit testing// 'userguide'  => MODPATH.'userguide',  // User guide and API documentation));

2、将modules/database/config/里的database.php复制到application/config/目录下

<?php defined('SYSPATH') OR die('No direct access allowed.');return array('default' => array('type'       => 'MySQL','connection' => array('hostname'   => 'localhost','database'   => 'kohana','username'   => 'root','password'   => 123456,'persistent' => FALSE,),'table_prefix' => '','charset'      => 'utf8','caching'      => FALSE,),'alternate' => array('type'       => 'PDO','connection' => array('dsn'        => 'mysql:host=localhost;dbname=kohana','username'   => 'root','password'   => 'r00tdb','persistent' => FALSE,),'table_prefix' => '','charset'      => 'utf8','caching'      => FALSE,),);
其中default为必须定义的

MySQL 数据库能接受下面的连接配置选项
字符串的主机名   hostname    *端口和套接字可以添加到主机名
例如:localhost:3306
字符串的套接字   socket
字符串的用户名   username
字符串的密码     password
布尔值的持久链接 persistent
字符串的数据库名 database


PDO 数据库能接受下列这些连接配置选项
字符串的数据源   dsn
字符串的用户名   username
字符串的密码     password
布尔值的持久链接 persistent
字符串的标识符   identifier