File tree Expand file tree Collapse file tree
user_guide_src/source/database Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -51,11 +51,16 @@ DSN in Universal Manner
5151You can also set a Data Source Name in universal manner (URL like). In that case DSNs must have this prototype:
5252
5353.. literalinclude :: configuration/003.php
54+ :lines: 11-14
5455
5556To override default config values when connecting with a universal version of the DSN string,
5657add the config variables as a query string:
5758
5859.. literalinclude :: configuration/004.php
60+ :lines: 11-15
61+
62+ .. literalinclude :: configuration/010.php
63+ :lines: 11-15
5964
6065.. note :: If you provide a DSN string and it is missing some valid settings (e.g., the
6166 database character set), which are present in the rest of the configuration
Original file line number Diff line number Diff line change 66
77class Database extends Config
88{
9- public $ default = [
9+ // ...
10+
11+ public array $ default = [
1012 'DSN ' => '' ,
1113 'hostname ' => 'localhost ' ,
1214 'username ' => 'root ' ,
1315 'password ' => '' ,
1416 'database ' => 'database_name ' ,
1517 'DBDriver ' => 'MySQLi ' ,
1618 'DBPrefix ' => '' ,
17- 'pConnect ' => true ,
19+ 'pConnect ' => false ,
1820 'DBDebug ' => true ,
1921 'charset ' => 'utf8 ' ,
2022 'DBCollat ' => 'utf8_general_ci ' ,
Original file line number Diff line number Diff line change 11<?php
22
3- $ default = [
4- 'DSN ' => 'DBDriver://username:password@hostname:port/database ' ,
3+ namespace Config ;
4+
5+ use CodeIgniter \Database \Config ;
6+
7+ class Database extends Config
8+ {
9+ // ...
10+
11+ public array $ default = [
12+ 'DSN ' => 'DBDriver://username:password@hostname:port/database ' ,
13+ // ...
14+ ];
15+
516 // ...
6- ];
17+ }
Original file line number Diff line number Diff line change 11<?php
22
3- // MySQLi
4- $ default = [
5- 'DSN ' => 'MySQLi://username:password@hostname:3306/database?charset=utf8&DBCollat=utf8_general_ci ' ,
3+ namespace Config ;
4+
5+ use CodeIgniter \Database \Config ;
6+
7+ class Database extends Config
8+ {
69 // ...
7- ];
810
9- // Postgre
10- $ default = [
11- 'DSN ' => 'Postgre://username:password@hostname:5432/database?charset=utf8&connect_timeout=5&sslmode=1 ' ,
11+ // MySQLi
12+ public array $ default = [
13+ 'DSN ' => 'MySQLi://username:password@hostname:3306/database?charset=utf8&DBCollat=utf8_general_ci ' ,
14+ // ...
15+ ];
16+
1217 // ...
13- ];
18+ }
Original file line number Diff line number Diff line change 11<?php
22
3- $ default ['failover ' ] = [
4- [
5- 'hostname ' => 'localhost1 ' ,
6- 'username ' => '' ,
7- 'password ' => '' ,
8- 'database ' => '' ,
9- 'DBDriver ' => 'MySQLi ' ,
10- 'DBPrefix ' => '' ,
11- 'pConnect ' => true ,
12- 'DBDebug ' => true ,
13- 'charset ' => 'utf8 ' ,
14- 'DBCollat ' => 'utf8_general_ci ' ,
15- 'swapPre ' => '' ,
16- 'encrypt ' => false ,
17- 'compress ' => false ,
18- 'strictOn ' => false ,
19- ],
20- [
21- 'hostname ' => 'localhost2 ' ,
22- 'username ' => '' ,
23- 'password ' => '' ,
24- 'database ' => '' ,
25- 'DBDriver ' => 'MySQLi ' ,
26- 'DBPrefix ' => '' ,
27- 'pConnect ' => true ,
28- 'DBDebug ' => true ,
29- 'charset ' => 'utf8 ' ,
30- 'DBCollat ' => 'utf8_general_ci ' ,
31- 'swapPre ' => '' ,
32- 'encrypt ' => false ,
33- 'compress ' => false ,
34- 'strictOn ' => false ,
35- ],
36- ];
3+ namespace Config ;
4+
5+ use CodeIgniter \Database \Config ;
6+
7+ class Database extends Config
8+ {
9+ // ...
10+
11+ public array $ default = [
12+ // ...
13+ 'failover ' => [
14+ [
15+ 'hostname ' => 'localhost1 ' ,
16+ 'username ' => '' ,
17+ 'password ' => '' ,
18+ 'database ' => '' ,
19+ 'DBDriver ' => 'MySQLi ' ,
20+ 'DBPrefix ' => '' ,
21+ 'pConnect ' => true ,
22+ 'DBDebug ' => true ,
23+ 'charset ' => 'utf8 ' ,
24+ 'DBCollat ' => 'utf8_general_ci ' ,
25+ 'swapPre ' => '' ,
26+ 'encrypt ' => false ,
27+ 'compress ' => false ,
28+ 'strictOn ' => false ,
29+ ],
30+ [
31+ 'hostname ' => 'localhost2 ' ,
32+ 'username ' => '' ,
33+ 'password ' => '' ,
34+ 'database ' => '' ,
35+ 'DBDriver ' => 'MySQLi ' ,
36+ 'DBPrefix ' => '' ,
37+ 'pConnect ' => true ,
38+ 'DBDebug ' => true ,
39+ 'charset ' => 'utf8 ' ,
40+ 'DBCollat ' => 'utf8_general_ci ' ,
41+ 'swapPre ' => '' ,
42+ 'encrypt ' => false ,
43+ 'compress ' => false ,
44+ 'strictOn ' => false ,
45+ ],
46+ ],
47+ // ...
48+ ];
49+
50+ // ...
51+ }
Original file line number Diff line number Diff line change 66
77class Database extends Config
88{
9- public $ test = [
9+ // ...
10+
11+ public array $ test = [
1012 'DSN ' => '' ,
1113 'hostname ' => 'localhost ' ,
1214 'username ' => 'root ' ,
Original file line number Diff line number Diff line change 11<?php
22
3- $ defaultGroup = 'test ' ;
3+ namespace Config ;
4+
5+ use CodeIgniter \Database \Config ;
6+
7+ class Database extends Config
8+ {
9+ // ...
10+
11+ public string $ defaultGroup = 'test ' ;
12+
13+ // ...
14+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Config ;
4+
5+ use CodeIgniter \Database \Config ;
6+
7+ class Database extends Config
8+ {
9+ // ...
10+
11+ // Postgre
12+ public array $ default = [
13+ 'DSN ' => 'Postgre://username:password@hostname:5432/database?charset=utf8&connect_timeout=5&sslmode=1 ' ,
14+ // ...
15+ ];
16+
17+ // ...
18+ }
You can’t perform that action at this time.
0 commit comments