Repository navigation
Expand file tree
/
Copy pathdatabase.connections.php
More file actions
105 lines (96 loc) · 3.67 KB
/
Copy pathdatabase.connections.php
File metadata and controls
105 lines (96 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
use Fleetbase\Support\Utils;
$host = env('DB_HOST', '127.0.0.1');
$database = env('DB_DATABASE', 'fleetbase');
$username = env('DB_USERNAME', 'fleetbase');
$password = env('DB_PASSWORD', '');
$databaseUrl = getenv('DATABASE_URL');
if (!empty($databaseUrl)) {
$url = Utils::parseUrl($databaseUrl);
$host = $url['host'];
$username = $url['user'];
if (isset($url['pass'])) {
$password = $url['pass'];
}
$database = substr($url['path'], 1);
}
$mysql_options = [
// Persistent connections keep the MySQL session alive in PHP's persistent pool
// after the PDO object is gone, and hand that same session to the next PDO
// built from the same DSN/user/password - including one built while another
// handle is still using it. Two handles then share one transaction: a COMMIT
// through either ends it for both, so the other's commit() raises
// "There is no active transaction" for a write that already committed, and the
// caller reports failure for data that landed. Laravel cannot detect this,
// because commit() gates on its own $transactions counter rather than on
// PDO::inTransaction() (Illuminate\Database\Concerns\ManagesTransactions).
//
// Off by default. Set DB_PERSISTENT=true only where the reconnect cost is
// measured and no request opens a transaction.
PDO::ATTR_PERSISTENT => env('DB_PERSISTENT', false),
PDO::ATTR_TIMEOUT => 5,
];
if (env('APP_ENV') === 'local') {
$mysql_options[PDO::ATTR_EMULATE_PREPARES] = true;
}
if (extension_loaded('pdo_mysql')) {
if (env('MYSQL_ATTR_SSL_CA')) {
$mysql_options[PDO::MYSQL_ATTR_SSL_CA] = env('MYSQL_ATTR_SSL_CA');
}
if (env('MYSQL_ATTR_SSL_CERT')) {
$mysql_options[PDO::MYSQL_ATTR_SSL_CERT] = env('MYSQL_ATTR_SSL_CERT');
}
if (env('MYSQL_ATTR_SSL_KEY')) {
$mysql_options[PDO::MYSQL_ATTR_SSL_KEY] = env('MYSQL_ATTR_SSL_KEY');
}
// Setting default SSL verification behavior based on environment
$mysql_options[PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = env('MYSQL_ATTR_SSL_VERIFY_SERVER_CERT', env('APP_ENV') === 'production');
}
/*
|--------------------------------------------------------------------------
| Database Connections
|--------------------------------------------------------------------------
|
| Here are each of the database connections setup for your application.
| Of course, examples of configuring each database platform that is
| supported by Laravel is shown below to make development simple.
|
|
| All database work in Laravel is done through the PHP PDO facilities
| so make sure you have the driver for your particular database of
| choice installed on your machine before you begin development.
|
*/
return [
'mysql' => [
'driver' => 'mysql',
'host' => $host,
'port' => env('DB_PORT', '3306'),
'database' => $database,
'username' => $username,
'password' => $password,
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
'options' => $mysql_options,
'pool' => [
'size' => env('DB_CONNECTION_POOL_SIZE', 25),
],
],
'sandbox' => [
'driver' => 'mysql',
'host' => $host,
'port' => env('SANDBOX_DB_PORT', env('DB_PORT', '3306')),
'database' => $database . '_sandbox',
'username' => $username,
'password' => $password,
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
'options' => $mysql_options,
],
];