Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| Database | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Config; |
| 4 | |
| 5 | use CodeIgniter\Database\Config; |
| 6 | |
| 7 | /** |
| 8 | * Database Configuration |
| 9 | */ |
| 10 | class Database extends Config |
| 11 | { |
| 12 | /** |
| 13 | * The directory that holds the Migrations and Seeds directories. |
| 14 | */ |
| 15 | public string $filesPath = APPPATH . 'Database' . DIRECTORY_SEPARATOR; |
| 16 | |
| 17 | /** |
| 18 | * Lets you choose which connection group to use if no other is specified. |
| 19 | */ |
| 20 | public string $defaultGroup = 'default'; |
| 21 | |
| 22 | /** |
| 23 | * The default database connection. |
| 24 | * |
| 25 | * @var array<string, mixed> |
| 26 | */ |
| 27 | public array $default = [ |
| 28 | 'DSN' => '', |
| 29 | 'hostname' => '', |
| 30 | 'username' => '', |
| 31 | 'password' => '', |
| 32 | 'database' => '', |
| 33 | 'DBDriver' => 'MySQLi', |
| 34 | 'DBPrefix' => '', |
| 35 | 'pConnect' => false, |
| 36 | 'DBDebug' => true, |
| 37 | 'charset' => 'utf8mb4', |
| 38 | 'DBCollat' => 'utf8mb4_unicode_ci', |
| 39 | 'swapPre' => '', |
| 40 | 'encrypt' => false, |
| 41 | 'compress' => false, |
| 42 | 'strictOn' => false, |
| 43 | 'failover' => [], |
| 44 | 'port' => 3306, |
| 45 | 'numberNative' => false, |
| 46 | 'foundRows' => false, |
| 47 | ]; |
| 48 | |
| 49 | // /** |
| 50 | // * Sample database connection for SQLite3. |
| 51 | // * |
| 52 | // * @var array<string, mixed> |
| 53 | // */ |
| 54 | // public array $default = [ |
| 55 | // 'database' => 'database.db', |
| 56 | // 'DBDriver' => 'SQLite3', |
| 57 | // 'DBPrefix' => '', |
| 58 | // 'DBDebug' => true, |
| 59 | // 'swapPre' => '', |
| 60 | // 'failover' => [], |
| 61 | // 'foreignKeys' => true, |
| 62 | // 'busyTimeout' => 1000, |
| 63 | // 'synchronous' => null, |
| 64 | // 'dateFormat' => [ |
| 65 | // 'date' => 'Y-m-d', |
| 66 | // 'datetime' => 'Y-m-d H:i:s', |
| 67 | // 'time' => 'H:i:s', |
| 68 | // ], |
| 69 | // ]; |
| 70 | |
| 71 | // /** |
| 72 | // * Sample database connection for Postgre. |
| 73 | // * |
| 74 | // * @var array<string, mixed> |
| 75 | // */ |
| 76 | // public array $default = [ |
| 77 | // 'DSN' => '', |
| 78 | // 'hostname' => 'localhost', |
| 79 | // 'username' => 'root', |
| 80 | // 'password' => 'root', |
| 81 | // 'database' => 'ci4', |
| 82 | // 'schema' => 'public', |
| 83 | // 'DBDriver' => 'Postgre', |
| 84 | // 'DBPrefix' => '', |
| 85 | // 'pConnect' => false, |
| 86 | // 'DBDebug' => true, |
| 87 | // 'charset' => 'utf8', |
| 88 | // 'swapPre' => '', |
| 89 | // 'failover' => [], |
| 90 | // 'port' => 5432, |
| 91 | // 'dateFormat' => [ |
| 92 | // 'date' => 'Y-m-d', |
| 93 | // 'datetime' => 'Y-m-d H:i:s', |
| 94 | // 'time' => 'H:i:s', |
| 95 | // ], |
| 96 | // ]; |
| 97 | |
| 98 | // /** |
| 99 | // * Sample database connection for SQLSRV. |
| 100 | // * |
| 101 | // * @var array<string, mixed> |
| 102 | // */ |
| 103 | // public array $default = [ |
| 104 | // 'DSN' => '', |
| 105 | // 'hostname' => 'localhost', |
| 106 | // 'username' => 'root', |
| 107 | // 'password' => 'root', |
| 108 | // 'database' => 'ci4', |
| 109 | // 'schema' => 'dbo', |
| 110 | // 'DBDriver' => 'SQLSRV', |
| 111 | // 'DBPrefix' => '', |
| 112 | // 'pConnect' => false, |
| 113 | // 'DBDebug' => true, |
| 114 | // 'charset' => 'utf8', |
| 115 | // 'swapPre' => '', |
| 116 | // 'encrypt' => false, |
| 117 | // 'failover' => [], |
| 118 | // 'port' => 1433, |
| 119 | // 'dateFormat' => [ |
| 120 | // 'date' => 'Y-m-d', |
| 121 | // 'datetime' => 'Y-m-d H:i:s', |
| 122 | // 'time' => 'H:i:s', |
| 123 | // ], |
| 124 | // ]; |
| 125 | |
| 126 | // /** |
| 127 | // * Sample database connection for OCI8. |
| 128 | // * |
| 129 | // * You may need the following environment variables: |
| 130 | // * NLS_LANG = 'AMERICAN_AMERICA.UTF8' |
| 131 | // * NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS' |
| 132 | // * NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS' |
| 133 | // * NLS_TIMESTAMP_TZ_FORMAT = 'YYYY-MM-DD HH24:MI:SS' |
| 134 | // * |
| 135 | // * @var array<string, mixed> |
| 136 | // */ |
| 137 | // public array $default = [ |
| 138 | // 'DSN' => 'localhost:1521/XEPDB1', |
| 139 | // 'username' => 'root', |
| 140 | // 'password' => 'root', |
| 141 | // 'DBDriver' => 'OCI8', |
| 142 | // 'DBPrefix' => '', |
| 143 | // 'pConnect' => false, |
| 144 | // 'DBDebug' => true, |
| 145 | // 'charset' => 'AL32UTF8', |
| 146 | // 'swapPre' => '', |
| 147 | // 'failover' => [], |
| 148 | // 'dateFormat' => [ |
| 149 | // 'date' => 'Y-m-d', |
| 150 | // 'datetime' => 'Y-m-d H:i:s', |
| 151 | // 'time' => 'H:i:s', |
| 152 | // ], |
| 153 | // ]; |
| 154 | |
| 155 | /** |
| 156 | * This database connection is used when running PHPUnit database tests. |
| 157 | * |
| 158 | * @var array<string, mixed> |
| 159 | */ |
| 160 | public array $tests = [ |
| 161 | 'DSN' => '', |
| 162 | 'hostname' => '127.0.0.1', |
| 163 | 'username' => '', |
| 164 | 'password' => '', |
| 165 | 'database' => ':memory:', |
| 166 | 'DBDriver' => 'SQLite3', |
| 167 | 'DBPrefix' => 'db_', // Needed to ensure we're working correctly with prefixes live. DO NOT REMOVE FOR CI DEVS |
| 168 | 'pConnect' => false, |
| 169 | 'DBDebug' => true, |
| 170 | 'charset' => 'utf8', |
| 171 | 'DBCollat' => '', |
| 172 | 'swapPre' => '', |
| 173 | 'encrypt' => false, |
| 174 | 'compress' => false, |
| 175 | 'strictOn' => true, |
| 176 | 'failover' => [], |
| 177 | 'port' => 3306, |
| 178 | 'foreignKeys' => true, |
| 179 | 'busyTimeout' => 1000, |
| 180 | 'synchronous' => null, |
| 181 | 'dateFormat' => [ |
| 182 | 'date' => 'Y-m-d', |
| 183 | 'datetime' => 'Y-m-d H:i:s', |
| 184 | 'time' => 'H:i:s', |
| 185 | ], |
| 186 | ]; |
| 187 | |
| 188 | public function __construct() |
| 189 | { |
| 190 | parent::__construct(); |
| 191 | |
| 192 | // Ensure that we always set the database group to 'tests' if |
| 193 | // we are currently running an automated test suite, so that |
| 194 | // we don't overwrite live data on accident. |
| 195 | if (ENVIRONMENT === 'testing') { |
| 196 | $this->defaultGroup = 'tests'; |
| 197 | } |
| 198 | } |
| 199 | } |