数据库配置
数据库配置文件
数据库配置文件 config/db.config.php, 返回一个配置数组
return [
'mysql' => [
'db' => $mysql('test')
],
'redis' => [
'cache' => $redis(1)
],
];
$mysql() 和 $redis() 匿名函数分别处理 mysql 和 redis 配置
$mysql = function (string $name) {
return [
'host' => '127.0.0.1',
'port' => '3306',
'user' => 'root',
'pass' => '123456',
'prefix' => '',
'charset' => 'utf8',
'name' => $name
];
};
$redis = function (int $db) {
return [
'host' => '127.0.0.1',
'port' => 6379,
'pass' => '',
'db' => $db,
'timeout' => 2.5
];
};
区分开发环境
复制 db.config.php 文件, 重命名为 .db.config.php, 系统会优先使用 . 开头的配置文件
不要将
.db.config.php加入版本管理系统