Skip to content

Commit c605069

Browse files
authored
Merge pull request #6049 from kenjis/fix-docs-database/configuration.rst
docs: improve database/configuration.rst
2 parents e09a5fe + 7501477 commit c605069

File tree

6 files changed

+57
-30
lines changed

6 files changed

+57
-30
lines changed

user_guide_src/source/database/configuration.rst

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Database Configuration
66
:local:
77
:depth: 2
88

9+
***********
10+
Config File
11+
***********
12+
913
CodeIgniter has a config file that lets you store your database
1014
connection values (username, password, database name, etc.). The config
1115
file is located at **app/Config/Database.php**. You can also set
@@ -22,6 +26,9 @@ while connecting to specify a group name.
2226
.. note:: The default location of the SQLite3 database is in the ``writable`` folder.
2327
If you want to change the location, you must set the full path to the new folder.
2428

29+
DSN
30+
===
31+
2532
Some database drivers (such as PDO, PostgreSQL, Oracle, ODBC) might
2633
require a full DSN string to be provided. If that is the case, you
2734
should use the 'DSN' configuration setting, as if you're using the
@@ -45,6 +52,9 @@ add the config variables as a query string:
4552
database character set), which are present in the rest of the configuration
4653
fields, CodeIgniter will append them.
4754

55+
Failovers
56+
=========
57+
4858
You can also specify failovers for the situation when the main connection cannot connect for some reason.
4959
These failovers can be specified by setting the failover for a connection like this:
5060

@@ -69,14 +79,18 @@ variable located in the config file:
6979
default we've used the word "default" for the primary connection,
7080
but it too can be renamed to something more relevant to your project.
7181

82+
defaultGroup
83+
============
84+
7285
You could modify the config file to detect the environment and automatically
7386
update the `defaultGroup` value to the correct one by adding the required logic
7487
within the class' constructor:
7588

7689
.. literalinclude:: configuration/008.php
7790

78-
Configuring With .env File
79-
--------------------------
91+
**************************
92+
Configuring with .env File
93+
**************************
8094

8195
You can also save your configuration values within a **.env** file with the current server's
8296
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
87101
database.default.password = '';
88102
database.default.database = 'ci4';
89103

90-
As with all other
91-
104+
**********************
92105
Explanation of Values:
93-
----------------------
106+
**********************
94107

95108
============== ===========================================================================================================
96109
Name Config Description
@@ -100,34 +113,28 @@ Explanation of Values:
100113
**username** The username used to connect to the database.
101114
**password** The password used to connect to the database.
102115
**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
104117
**DBPrefix** An optional table prefix which will added to the table name when running
105118
:doc:`Query Builder <query_builder>` queries. This permits multiple CodeIgniter
106119
installations to share one database.
107120
**pConnect** true/false (boolean) - Whether to use a persistent connection.
108121
**DBDebug** true/false (boolean) - Whether database errors should be displayed.
109122
**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
115125
applications where you might run manually written queries, and need the prefix to still be
116126
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.
118128
**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).
131138
**strictOn** true/false (boolean) - Whether to force "Strict Mode" connections, good for ensuring strict SQL
132139
while developing an application.
133140
**port** The database port number. To use this value you have to add a line to the database config array.

user_guide_src/source/database/configuration/001.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Database extends Config
2323
'compress' => false,
2424
'strictOn' => false,
2525
'failover' => [],
26+
'port' => 3306,
2627
];
2728

2829
// ...
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
<?php
22

33
// PDO
4-
$default['DSN'] = 'pgsql:host=localhost;port=5432;dbname=database_name';
4+
$default = [
5+
'DSN' => 'pgsql:host=localhost;port=5432;dbname=database_name',
6+
// ...
7+
];
58

69
// Oracle
7-
$default['DSN'] = '//localhost/XE';
10+
$default = [
11+
'DSN' => '//localhost/XE',
12+
// ...
13+
];
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
<?php
22

3-
$default['DSN'] = 'DBDriver://username:password@hostname:port/database';
3+
$default = [
4+
'DSN' => 'DBDriver://username:password@hostname:port/database',
5+
// ...
6+
];
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
<?php
22

33
// MySQLi
4-
$default['DSN'] = 'MySQLi://username:password@hostname:3306/database?charset=utf8&DBCollat=utf8_general_ci';
4+
$default = [
5+
'DSN' => 'MySQLi://username:password@hostname:3306/database?charset=utf8&DBCollat=utf8_general_ci',
6+
// ...
7+
];
8+
59
// Postgre
6-
$default['DSN'] = 'Postgre://username:password@hostname:5432/database?charset=utf8&connect_timeout=5&sslmode=1';
10+
$default = [
11+
'DSN' => 'Postgre://username:password@hostname:5432/database?charset=utf8&connect_timeout=5&sslmode=1',
12+
// ...
13+
];
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
<?php
22

3-
$default['port'] = 5432;
3+
$default = [
4+
// ...
5+
'port' => 5432,
6+
];

0 commit comments

Comments
 (0)