Skip to content

Commit 2c2b3cd

Browse files
authored
Merge pull request #8693 from kenjis/refactor-db-properties
refactor: DB config properties
2 parents 8b7dfcb + 8cd8d7c commit 2c2b3cd

File tree

5 files changed

+118
-12
lines changed

5 files changed

+118
-12
lines changed

app/Config/Database.php

Lines changed: 108 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@
1010
class Database extends Config
1111
{
1212
/**
13-
* The directory that holds the Migrations
14-
* and Seeds directories.
13+
* The directory that holds the Migrations and Seeds directories.
1514
*/
1615
public string $filesPath = APPPATH . 'Database' . DIRECTORY_SEPARATOR;
1716

1817
/**
19-
* Lets you choose which connection group to
20-
* use if no other is specified.
18+
* Lets you choose which connection group to use if no other is specified.
2119
*/
2220
public string $defaultGroup = 'default';
2321

@@ -52,9 +50,113 @@ class Database extends Config
5250
],
5351
];
5452

53+
// /**
54+
// * Sample database connection for SQLite3.
55+
// *
56+
// * @var array<string, mixed>
57+
// */
58+
// public array $default = [
59+
// 'database' => 'database.db',
60+
// 'DBDriver' => 'SQLite3',
61+
// 'DBPrefix' => '',
62+
// 'DBDebug' => true,
63+
// 'swapPre' => '',
64+
// 'failover' => [],
65+
// 'foreignKeys' => true,
66+
// 'busyTimeout' => 1000,
67+
// 'dateFormat' => [
68+
// 'date' => 'Y-m-d',
69+
// 'datetime' => 'Y-m-d H:i:s',
70+
// 'time' => 'H:i:s',
71+
// ],
72+
// ];
73+
74+
// /**
75+
// * Sample database connection for Postgre.
76+
// *
77+
// * @var array<string, mixed>
78+
// */
79+
// public array $default = [
80+
// 'DSN' => '',
81+
// 'hostname' => 'localhost',
82+
// 'username' => 'root',
83+
// 'password' => 'root',
84+
// 'database' => 'ci4',
85+
// 'schema' => 'public',
86+
// 'DBDriver' => 'Postgre',
87+
// 'DBPrefix' => '',
88+
// 'pConnect' => false,
89+
// 'DBDebug' => true,
90+
// 'charset' => 'utf8',
91+
// 'swapPre' => '',
92+
// 'failover' => [],
93+
// 'port' => 5432,
94+
// 'dateFormat' => [
95+
// 'date' => 'Y-m-d',
96+
// 'datetime' => 'Y-m-d H:i:s',
97+
// 'time' => 'H:i:s',
98+
// ],
99+
// ];
100+
101+
// /**
102+
// * Sample database connection for SQLSRV.
103+
// *
104+
// * @var array<string, mixed>
105+
// */
106+
// public array $default = [
107+
// 'DSN' => '',
108+
// 'hostname' => 'localhost',
109+
// 'username' => 'root',
110+
// 'password' => 'root',
111+
// 'database' => 'ci4',
112+
// 'schema' => 'dbo',
113+
// 'DBDriver' => 'SQLSRV',
114+
// 'DBPrefix' => '',
115+
// 'pConnect' => false,
116+
// 'DBDebug' => true,
117+
// 'charset' => 'utf8',
118+
// 'swapPre' => '',
119+
// 'encrypt' => false,
120+
// 'failover' => [],
121+
// 'port' => 1433,
122+
// 'dateFormat' => [
123+
// 'date' => 'Y-m-d',
124+
// 'datetime' => 'Y-m-d H:i:s',
125+
// 'time' => 'H:i:s',
126+
// ],
127+
// ];
128+
129+
// /**
130+
// * Sample database connection for OCI8.
131+
// *
132+
// * You may need the following environment variables:
133+
// * NLS_LANG = 'AMERICAN_AMERICA.UTF8'
134+
// * NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'
135+
// * NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS'
136+
// * NLS_TIMESTAMP_TZ_FORMAT = 'YYYY-MM-DD HH24:MI:SS'
137+
// *
138+
// * @var array<string, mixed>
139+
// */
140+
// public array $default = [
141+
// 'DSN' => 'localhost:1521/XEPDB1',
142+
// 'username' => 'root',
143+
// 'password' => 'root',
144+
// 'DBDriver' => 'OCI8',
145+
// 'DBPrefix' => '',
146+
// 'pConnect' => false,
147+
// 'DBDebug' => true,
148+
// 'charset' => 'AL32UTF8',
149+
// 'swapPre' => '',
150+
// 'failover' => [],
151+
// 'dateFormat' => [
152+
// 'date' => 'Y-m-d',
153+
// 'datetime' => 'Y-m-d H:i:s',
154+
// 'time' => 'H:i:s',
155+
// ],
156+
// ];
157+
55158
/**
56-
* This database connection is used when
57-
* running PHPUnit database tests.
159+
* This database connection is used when running PHPUnit database tests.
58160
*
59161
* @var array<string, mixed>
60162
*/

phpstan-baseline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3168,7 +3168,7 @@
31683168
];
31693169
$ignoreErrors[] = [
31703170
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
3171-
'count' => 6,
3171+
'count' => 4,
31723172
'path' => __DIR__ . '/system/Database/MySQLi/Forge.php',
31733173
];
31743174
$ignoreErrors[] = [

system/Database/BaseConnection.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ abstract class BaseConnection implements ConnectionInterface
144144
*
145145
* @var string
146146
*/
147-
protected $charset = 'utf8mb4';
147+
protected $charset = '';
148148

149149
/**
150150
* Collation
@@ -153,7 +153,7 @@ abstract class BaseConnection implements ConnectionInterface
153153
*
154154
* @var string
155155
*/
156-
protected $DBCollat = 'utf8mb4_general_ci';
156+
protected $DBCollat = '';
157157

158158
/**
159159
* Swap Prefix
@@ -181,7 +181,9 @@ abstract class BaseConnection implements ConnectionInterface
181181
*
182182
* Whether we're running in strict SQL mode.
183183
*
184-
* @var bool
184+
* @var bool|null
185+
*
186+
* @deprecated 4.5.0 Will move to MySQLi\Connection.
185187
*/
186188
protected $strictOn;
187189

system/Database/MySQLi/Forge.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ protected function _createTableAttributes(array $attributes): string
116116
}
117117
}
118118

119-
if (! empty($this->db->charset) && ! strpos($sql, 'CHARACTER SET') && ! strpos($sql, 'CHARSET')) {
119+
if ($this->db->charset !== '' && ! strpos($sql, 'CHARACTER SET') && ! strpos($sql, 'CHARSET')) {
120120
$sql .= ' DEFAULT CHARACTER SET = ' . $this->db->escapeString($this->db->charset);
121121
}
122122

123-
if (! empty($this->db->DBCollat) && ! strpos($sql, 'COLLATE')) {
123+
if ($this->db->DBCollat !== '' && ! strpos($sql, 'COLLATE')) {
124124
$sql .= ' COLLATE = ' . $this->db->escapeString($this->db->DBCollat);
125125
}
126126

user_guide_src/source/changelogs/v4.5.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,8 @@ Deprecations
502502
- **FeatureTestTrait:** The feature that the ``call()`` and ``withRoutes()``
503503
methods accept the lowercase HTTP methods has been deprecated. Use correct
504504
uppercase HTTP methods instead.
505+
- **Database:** The ``BaseConnection::$strictOn`` has been deprecated. It will be
506+
moved to ``MySQLi\Connection`` in the future.
505507

506508
**********
507509
Bugs Fixed

0 commit comments

Comments
 (0)