Skip to content

Commit 01e1a46

Browse files
authored
Merge pull request #8539 from kenjis/fix-db-dateFormat-merge
[4.5] fix: $db->dateFormat merge
2 parents 09b48d5 + f5a28e2 commit 01e1a46

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

system/Database/BaseConnection.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,16 +366,17 @@ abstract class BaseConnection implements ConnectionInterface
366366
*/
367367
public function __construct(array $params)
368368
{
369+
if (isset($params['dateFormat'])) {
370+
$this->dateFormat = array_merge($this->dateFormat, $params['dateFormat']);
371+
unset($params['dateFormat']);
372+
}
373+
369374
foreach ($params as $key => $value) {
370375
if (property_exists($this, $key)) {
371376
$this->{$key} = $value;
372377
}
373378
}
374379

375-
if (isset($params['dateFormat'])) {
376-
$this->dateFormat = array_merge($this->dateFormat, $params['dateFormat']);
377-
}
378-
379380
$queryClass = str_replace('Connection', 'Query', static::class);
380381

381382
if (class_exists($queryClass)) {

tests/system/Database/BaseConnectionTest.php

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,27 @@
2626
final class BaseConnectionTest extends CIUnitTestCase
2727
{
2828
private array $options = [
29-
'DSN' => '',
30-
'hostname' => 'localhost',
31-
'username' => 'first',
32-
'password' => 'last',
33-
'database' => 'dbname',
34-
'DBDriver' => 'MockDriver',
35-
'DBPrefix' => 'test_',
36-
'pConnect' => true,
37-
'DBDebug' => true,
38-
'charset' => 'utf8mb4',
39-
'DBCollat' => 'utf8mb4_general_ci',
40-
'swapPre' => '',
41-
'encrypt' => false,
42-
'compress' => false,
43-
'strictOn' => true,
44-
'failover' => [],
29+
'DSN' => '',
30+
'hostname' => 'localhost',
31+
'username' => 'first',
32+
'password' => 'last',
33+
'database' => 'dbname',
34+
'DBDriver' => 'MockDriver',
35+
'DBPrefix' => 'test_',
36+
'pConnect' => true,
37+
'DBDebug' => true,
38+
'charset' => 'utf8mb4',
39+
'DBCollat' => 'utf8mb4_general_ci',
40+
'swapPre' => '',
41+
'encrypt' => false,
42+
'compress' => false,
43+
'strictOn' => true,
44+
'failover' => [],
45+
'dateFormat' => [
46+
'date' => 'Y-m-d',
47+
'datetime' => 'Y-m-d H:i:s',
48+
'time' => 'H:i:s',
49+
],
4550
];
4651
private array $failoverOptions = [
4752
'DSN' => '',

0 commit comments

Comments
 (0)