database.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. use think\facade\Env;
  3. return [
  4. // 默认使用的数据库连接配置
  5. 'default' => Env::get('database.driver', 'mysql'),
  6. // 自定义时间查询规则
  7. 'time_query_rule' => [],
  8. // 自动写入时间戳字段
  9. // true为自动识别类型 false关闭
  10. // 字符串则明确指定时间字段类型 支持 int timestamp datetime date
  11. 'auto_timestamp' => true,
  12. // 时间字段取出后的默认时间格式
  13. 'datetime_format' => 'Y-m-d H:i:s',
  14. // 数据库连接配置信息
  15. 'connections' => [
  16. 'mysql' => [
  17. // 数据库类型
  18. 'type' => Env::get('database.type', 'mysql'),
  19. 'hostname' => Env::get('database.hostname', '127.0.0.1'),
  20. 'database' => Env::get('database.database', ''),
  21. 'username' => Env::get('database.username', 'root'),
  22. 'password' => Env::get('database.password', ''),
  23. 'hostport' => Env::get('database.hostport', '3306'),
  24. // 数据库编码默认采用utf8
  25. 'charset' => Env::get('database.charset', 'utf8'),
  26. // 数据库表前缀
  27. 'prefix' => Env::get('database.prefix', 'db_'),
  28. // 数据库连接参数
  29. 'params' => [],
  30. // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
  31. 'deploy' => 0,
  32. // 数据库读写是否分离 主从式有效
  33. 'rw_separate' => false,
  34. // 读写分离后 主服务器数量
  35. 'master_num' => 1,
  36. // 指定从服务器序号
  37. 'slave_no' => '',
  38. // 是否严格检查字段是否存在
  39. 'fields_strict' => true,
  40. // 是否需要断线重连
  41. 'break_reconnect' => true,
  42. // 监听SQL
  43. 'trigger_sql' => true,
  44. // 开启字段缓存
  45. 'fields_cache' => false,
  46. // 字段缓存路径
  47. 'schema_cache_path' => app()->getRuntimePath() . 'schema' . DIRECTORY_SEPARATOR,
  48. ],
  49. // 更多的数据库配置信息
  50. ],
  51. ];