@@ -6,6 +6,10 @@ Database Configuration
6
6
:local:
7
7
:depth: 2
8
8
9
+ ***********
10
+ Config File
11
+ ***********
12
+
9
13
CodeIgniter has a config file that lets you store your database
10
14
connection values (username, password, database name, etc.). The config
11
15
file is located at **app/Config/Database.php **. You can also set
@@ -22,6 +26,9 @@ while connecting to specify a group name.
22
26
.. note :: The default location of the SQLite3 database is in the ``writable`` folder.
23
27
If you want to change the location, you must set the full path to the new folder.
24
28
29
+ DSN
30
+ ===
31
+
25
32
Some database drivers (such as PDO, PostgreSQL, Oracle, ODBC) might
26
33
require a full DSN string to be provided. If that is the case, you
27
34
should use the 'DSN' configuration setting, as if you're using the
@@ -45,6 +52,9 @@ add the config variables as a query string:
45
52
database character set), which are present in the rest of the configuration
46
53
fields, CodeIgniter will append them.
47
54
55
+ Failovers
56
+ =========
57
+
48
58
You can also specify failovers for the situation when the main connection cannot connect for some reason.
49
59
These failovers can be specified by setting the failover for a connection like this:
50
60
@@ -69,14 +79,18 @@ variable located in the config file:
69
79
default we've used the word "default" for the primary connection,
70
80
but it too can be renamed to something more relevant to your project.
71
81
82
+ defaultGroup
83
+ ============
84
+
72
85
You could modify the config file to detect the environment and automatically
73
86
update the `defaultGroup ` value to the correct one by adding the required logic
74
87
within the class' constructor:
75
88
76
89
.. literalinclude :: configuration/008.php
77
90
78
- Configuring With .env File
79
- --------------------------
91
+ **************************
92
+ Configuring with .env File
93
+ **************************
80
94
81
95
You can also save your configuration values within a **.env ** file with the current server's
82
96
database settings. You only need to enter the values that change from what is in the
@@ -87,10 +101,9 @@ default group's configuration settings. The values should be name following this
87
101
database.default.password = '';
88
102
database.default.database = 'ci4';
89
103
90
- As with all other
91
-
104
+ **********************
92
105
Explanation of Values:
93
- ----------------------
106
+ **********************
94
107
95
108
============== ===========================================================================================================
96
109
Name Config Description
@@ -100,34 +113,28 @@ Explanation of Values:
100
113
**username ** The username used to connect to the database.
101
114
**password ** The password used to connect to the database.
102
115
**database ** The name of the database you want to connect to.
103
- **DBDriver ** The database type. e.g.,: MySQLi, Postgre , etc. The case must match the driver name
116
+ **DBDriver ** The database type. e.g.,: `` MySQLi ``, `` Postgres `` , etc. The case must match the driver name
104
117
**DBPrefix ** An optional table prefix which will added to the table name when running
105
118
:doc: `Query Builder <query_builder >` queries. This permits multiple CodeIgniter
106
119
installations to share one database.
107
120
**pConnect ** true/false (boolean) - Whether to use a persistent connection.
108
121
**DBDebug ** true/false (boolean) - Whether database errors should be displayed.
109
122
**charset ** The character set used in communicating with the database.
110
- **DBCollat ** The character collation used in communicating with the database
111
-
112
- .. note:: Only used in the 'MySQLi' driver.
113
-
114
- **swapPre ** A default table prefix that should be swapped with dbprefix. This is useful for distributed
123
+ **DBCollat ** The character collation used in communicating with the database (``MySQLi `` only)
124
+ **swapPre ** A default table prefix that should be swapped with ``DBPrefix ``. This is useful for distributed
115
125
applications where you might run manually written queries, and need the prefix to still be
116
126
customizable by the end user.
117
- **schema ** The database schema, default value varies by driver. Used by PostgreSQL and SQLSRV drivers.
127
+ **schema ** The database schema, default value varies by driver. Used by `` Postgres `` and `` SQLSRV `` drivers.
118
128
**encrypt ** Whether or not to use an encrypted connection.
119
-
120
- - 'sqlsrv' and 'pdo/sqlsrv' drivers accept true/false
121
- - 'MySQLi' and 'pdo/mysql' drivers accept an array with the following options:
122
-
123
- - 'ssl_key' - Path to the private key file
124
- - 'ssl_cert' - Path to the public key certificate file
125
- - 'ssl_ca' - Path to the certificate authority file
126
- - 'ssl_capath' - Path to a directory containing trusted CA certificates in PEM format
127
- - 'ssl_cipher' - List of *allowed * ciphers to be used for the encryption, separated by colons (':')
128
- - 'ssl_verify' - true/false; Whether to verify the server certificate or not ('MySQLi' only)
129
-
130
- **compress ** Whether or not to use client compression (MySQL only).
129
+ ``SQLSRV `` drivers accept true/false
130
+ ``MySQLi `` drivers accept an array with the following options:
131
+ * ``ssl_key `` - Path to the private key file
132
+ * ``ssl_cert `` - Path to the public key certificate file
133
+ * ``ssl_ca `` - Path to the certificate authority file
134
+ * ``ssl_capath `` - Path to a directory containing trusted CA certificates in PEM format
135
+ * ``ssl_cipher `` - List of *allowed * ciphers to be used for the encryption, separated by colons (``: ``)
136
+ * ``ssl_verify `` - true/false; Whether to verify the server certificate or not (``MySQLi `` only)
137
+ **compress ** Whether or not to use client compression (``MySQLi `` only).
131
138
**strictOn ** true/false (boolean) - Whether to force "Strict Mode" connections, good for ensuring strict SQL
132
139
while developing an application.
133
140
**port ** The database port number. To use this value you have to add a line to the database config array.
0 commit comments