• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

laraveldatabases.php

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
 1 <?php
 2 
 3 function _make_mysql($host, $port, $username, $password, $dbs, $prefix="mysql_") {
 4     $data = [];
 5     $hosts = explode('|', $host);
 6     if (sizeof($hosts) == 1) {
 7         $host = ['host' => $hosts[0]];
 8     } else {
 9         $host = [
10             'write' => ['host' => $hosts[0]],
11             'read' => ['host' => $hosts[1]]
12         ];
13     }
14 
15     foreach ($dbs as $key => $db) {
16         if (!is_string($key)) {
17             $key = $db;
18         }
19         $config = [
20             'driver'    => 'mysql',
21             'port'      => $port,
22             'database'  => $db,
23             'username'  => $username,
24             'password'  => $password,
25             'charset'   => 'utf8',
26             'collation' => 'utf8_unicode_ci',
27             'prefix'    => '',
28             'strict'    => false
29         ];
30         $data[$prefix.$key] = array_merge($config, $host);
31     }
32     return $data;
33 }
34 
35 function _make_mongo($host, $port, $dbs, $prefix="mongo_") {
36     $data = [];
37     foreach ($dbs as $db) {
38         $data[$prefix.$db] = [
39             'driver'    => 'mongodb',
40             'host'    => $host,
41             'port'    => $port,
42             'database'  => $db
43         ];
44     }
45     return $data;
46 }
47 
48 $admin_db = env('APP_MODE') == 0 ? 'admin' : 'cooperate';
49 $gege_db = env('APP_ENV') == 'production' ? 'gege' : 'moge';
50 $connections = array_merge(
51         _make_mysql(env('DB_MYSQL_HOST', '127.0.0.1'), env('DB_MYSQL_PORT', 3306), env('DB_MYSQL_USERNAME', 'root'), env('DB_MYSQL_PASSWORD', ''),
52             ['admin' => $admin_db]),
53         _make_mysql(env('DB_MYSQL_EBOX_HOST', '127.0.0.1'), env('DB_MYSQL_EBOX_PORT', 3306), env('DB_MYSQL_EBOX_USERNAME', 'root'), env('DB_MYSQL_EBOX_PASSWORD', ''),
54             ['ebox_v2','ebox_kz', 'ebox_order', 'ebox_pickup', 'ebox_notify', 'ebox_media', 'ebox_charge','gege' => $gege_db], 'mysql_'),
55         _make_mongo(env('DB_MONGO_HOST', '127.0.0.1'), env('DB_MONGO_PORT', 27017),
56             ['user', 'weixin', 'delivery', 'ebox','store', 'media']),
57         _make_mongo(env('DB_MONGO_OPENPLATFORM_HOST', '127.0.0.1'), env('DB_MONGO_OPENPLATFORM_PORT', 27017),
58             ['kuaidi_weixin','openplatform' ], "mongoext_"),
59 
60         _make_mysql(env('DB_MYSQL_STATS_HOST', '127.0.0.1'), env('DB_MYSQL_STATS_PORT', 3306), env('DB_MYSQL_STATS_USERNAME', 'root'), env('DB_MYSQL_STATS_PASSWORD', ''),
61             ['user'], 'stats_'),
62         _make_mysql(env('DB_MYSQL_SYNC_HOST', '127.0.0.1'), env('DB_MYSQL_SYNC_PORT', 3306), env('DB_MYSQL_SYNC_USERNAME', 'root'), env('DB_MYSQL_SYNC_PASSWORD', ''),
63             ['syncdb'], 'syncdb_')
64     );
65 
66 return [
67     'fetch' => PDO::FETCH_CLASS,
68     'default' => env('DB_DEFAULT_CONNECTION', 'mysql_admin'),
69     'connections' => array_merge([], $connections),
70 
71     'migrations' => 'migrations',
72     'redis' => [
73         'cluster' => false,
74         'default' => [
75             'host' => env('DB_REDIS_HOST', '127.0.0.1'),
76             'port' => 6379,
77             'database' => 0,
78         ],
79     ],
80 
81 ];

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP简单实用的缓存函数发布时间:2022-07-10
下一篇:
php设置error_reporting(0)和ini_set('display_errors',0)之后,还是显示错误 ...发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap