Skip to content

Commit b3fca93

Browse files
committed
docs: add how to set database.default.encrypt with .env
1 parent 8705f56 commit b3fca93

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

user_guide_src/source/database/configuration.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,19 @@ default group's configuration settings. The values should be name following this
104104
database.default.password = '';
105105
database.default.database = 'ci4';
106106

107-
.. important:: You cannot add a new property by setting environment variables,
108-
nor change a scalar value to an array. See :ref:`env-var-replacements-for-data`.
107+
But you cannot add a new property by setting environment variables, nor change a
108+
scalar value to an array. See :ref:`env-var-replacements-for-data` for details.
109+
110+
So if you want to use SSL with MySQL, you need a hack. For example, set the array
111+
values as a JSON string in your **.env** file:
112+
113+
::
114+
115+
database.default.encrypt = {"ssl_verify":true,"ssl_ca":"/var/www/html/BaltimoreCyberTrustRoot.crt.pem"}
116+
117+
and decode it in the constructor in the Config class:
118+
119+
.. literalinclude:: configuration/009.php
109120

110121
**********************
111122
Explanation of Values:
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Config;
4+
5+
use CodeIgniter\Database\Config;
6+
7+
/**
8+
* Database Configuration
9+
*/
10+
class Database extends Config
11+
{
12+
// ...
13+
14+
public function __construct()
15+
{
16+
// ...
17+
18+
$array = json_decode($this->default['encrypt'], true);
19+
if (is_array($array)) {
20+
$this->default['encrypt'] = $array;
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)