database.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. use Illuminate\Support\Str;
  3. $mysql = "mysql";// 默认
  4. if (app()->runningInConsole()) {//命令行请求
  5. // $command = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : '';
  6. // if ($command === 'command:insert_cloud') {
  7. // // 有人云数据
  8. // $mysql = "mysql_001";
  9. // }
  10. }else{// HTTP请求
  11. //账套
  12. // $zt = $_SERVER['HTTP_ZT'];
  13. // if($zt === '001') $mysql = "mysql_001";
  14. // if($zt === '002') $mysql = "mysql_002";
  15. }
  16. return [
  17. /*
  18. |--------------------------------------------------------------------------
  19. | Default Database Connection Name
  20. |--------------------------------------------------------------------------
  21. |
  22. | Here you may specify which of the database connections below you wish
  23. | to use as your default connection for all database work. Of course
  24. | you may use many connections at once using the Database library.
  25. |
  26. */
  27. 'default' => env('DB_CONNECTION', 'mysql'),
  28. // 'default' => $mysql,
  29. /*
  30. |--------------------------------------------------------------------------
  31. | Database Connections
  32. |--------------------------------------------------------------------------
  33. |
  34. | Here are each of the database connections setup for your application.
  35. | Of course, examples of configuring each database platform that is
  36. | supported by Laravel is shown below to make development simple.
  37. |
  38. |
  39. | All database work in Laravel is done through the PHP PDO facilities
  40. | so make sure you have the driver for your particular database of
  41. | choice installed on your machine before you begin development.
  42. |
  43. */
  44. 'connections' => [
  45. 'sqlite' => [
  46. 'driver' => 'sqlite',
  47. 'url' => env('DATABASE_URL'),
  48. 'database' => env('DB_DATABASE', database_path('database.sqlite')),
  49. 'prefix' => '',
  50. 'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
  51. ],
  52. 'mysql' => [
  53. 'driver' => 'mysql',
  54. 'url' => env('DATABASE_URL'),
  55. 'host' => env('DB_HOST', '127.0.0.1'),
  56. 'port' => env('DB_PORT', '3306'),
  57. 'database' => env('DB_DATABASE', 'forge'),
  58. 'username' => env('DB_USERNAME', 'forge'),
  59. 'password' => env('DB_PASSWORD', ''),
  60. 'unix_socket' => env('DB_SOCKET', ''),
  61. 'charset' => 'utf8mb4',
  62. 'collation' => 'utf8mb4_unicode_ci',
  63. 'prefix' => '',
  64. 'prefix_indexes' => true,
  65. 'strict' => false,
  66. 'engine' => null,
  67. 'options' => extension_loaded('pdo_mysql') ? array_filter([
  68. PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
  69. ]) : [],
  70. ],
  71. 'mysql_001' => [
  72. 'driver' => 'mysql',
  73. 'url' => env('DATABASE_URL'),
  74. 'host' => env('DB_HOST', '127.0.0.1'),
  75. 'port' => env('DB_PORT', '3306'),
  76. 'database' => env('DB_DATABASE_001', 'forge'),
  77. 'username' => env('DB_USERNAME', 'forge'),
  78. 'password' => env('DB_PASSWORD', ''),
  79. 'unix_socket' => env('DB_SOCKET', ''),
  80. 'charset' => 'utf8mb4',
  81. 'collation' => 'utf8mb4_unicode_ci',
  82. 'prefix' => '',
  83. 'prefix_indexes' => true,
  84. 'strict' => false,
  85. 'engine' => null,
  86. 'options' => extension_loaded('pdo_mysql') ? array_filter([
  87. PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
  88. ]) : [],
  89. ],
  90. 'mysql_002' => [
  91. 'driver' => 'mysql',
  92. 'url' => env('DATABASE_URL'),
  93. 'host' => env('DB_HOST', '127.0.0.1'),
  94. 'port' => env('DB_PORT', '3306'),
  95. 'database' => env('DB_DATABASE_002', 'forge'),
  96. 'username' => env('DB_USERNAME', 'forge'),
  97. 'password' => env('DB_PASSWORD', ''),
  98. 'unix_socket' => env('DB_SOCKET', ''),
  99. 'charset' => 'utf8mb4',
  100. 'collation' => 'utf8mb4_unicode_ci',
  101. 'prefix' => '',
  102. 'prefix_indexes' => true,
  103. 'strict' => false,
  104. 'engine' => null,
  105. 'options' => extension_loaded('pdo_mysql') ? array_filter([
  106. PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
  107. ]) : [],
  108. ],
  109. 'pgsql' => [
  110. 'driver' => 'pgsql',
  111. 'url' => env('DATABASE_URL'),
  112. 'host' => env('DB_HOST', '127.0.0.1'),
  113. 'port' => env('DB_PORT', '5432'),
  114. 'database' => env('DB_DATABASE', 'forge'),
  115. 'username' => env('DB_USERNAME', 'forge'),
  116. 'password' => env('DB_PASSWORD', ''),
  117. 'charset' => 'utf8',
  118. 'prefix' => '',
  119. 'prefix_indexes' => true,
  120. 'schema' => 'public',
  121. 'sslmode' => 'prefer',
  122. ],
  123. 'sqlsrv' => [
  124. 'driver' => 'sqlsrv',
  125. 'url' => env('DATABASE_URL'),
  126. 'host' => env('DB_HOST', 'localhost'),
  127. 'port' => env('DB_PORT', '1433'),
  128. 'database' => env('DB_DATABASE', 'forge'),
  129. 'username' => env('DB_USERNAME', 'forge'),
  130. 'password' => env('DB_PASSWORD', ''),
  131. 'charset' => 'utf8',
  132. 'prefix' => '',
  133. 'prefix_indexes' => true,
  134. ],
  135. 'sqlsrvs' => [
  136. 'driver' => 'sqlsrv',
  137. 'host' => env('SQLSRV_HOST'),
  138. 'port' => env('SQLSRV_PORT'),
  139. 'database' => env('SQLSRV_DATABASE'),
  140. 'username' => env('SQLSRV_USERNAME'),
  141. 'password' => env('SQLSRV_PASSWORD'),
  142. ],
  143. ],
  144. /*
  145. |--------------------------------------------------------------------------
  146. | Migration Repository Table
  147. |--------------------------------------------------------------------------
  148. |
  149. | This table keeps track of all the migrations that have already run for
  150. | your application. Using this information, we can determine which of
  151. | the migrations on disk haven't actually been run in the database.
  152. |
  153. */
  154. 'migrations' => 'migrations',
  155. /*
  156. |--------------------------------------------------------------------------
  157. | Redis Databases
  158. |--------------------------------------------------------------------------
  159. |
  160. | Redis is an open source, fast, and advanced key-value store that also
  161. | provides a richer body of commands than a typical key-value system
  162. | such as APC or Memcached. Laravel makes it easy to dig right in.
  163. |
  164. */
  165. 'redis' => [
  166. 'client' => env('REDIS_CLIENT', 'phpredis'),
  167. 'options' => [
  168. 'cluster' => env('REDIS_CLUSTER', 'redis'),
  169. 'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
  170. ],
  171. 'default' => [
  172. 'url' => env('REDIS_URL'),
  173. 'host' => env('REDIS_HOST', '127.0.0.1'),
  174. 'password' => env('REDIS_PASSWORD', null),
  175. 'port' => env('REDIS_PORT', '6379'),
  176. 'database' => env('REDIS_DB', '0'),
  177. ],
  178. 'cache' => [
  179. 'url' => env('REDIS_URL'),
  180. 'host' => env('REDIS_HOST', '127.0.0.1'),
  181. 'password' => env('REDIS_PASSWORD', null),
  182. 'port' => env('REDIS_PORT', '6379'),
  183. 'database' => env('REDIS_CACHE_DB', '1'),
  184. ],
  185. ],
  186. ];