【发布时间】:2021-01-16 13:05:12
【问题描述】:
我想用codeigniter 4和postgresql做一个项目我已经看过几个例子,我什至阅读了文档,但是连接数据库时仍然显示错误。
我的文件 .env 是这样的:
# database.tests.hostname = localhost
# database.tests.database = postgres_test
# database.tests.username = test
# database.tests.password = test123
# database.tests.DBDriver = postgre
还有我的文件 config\App.php
public $tests = [
'DSN' => 'pgsql:host=localhost;port=5432;dbname=database_name',
'hostname' => 'localhost',
'username' => 'test',
'password' => 'test123',
'database' => 'postgres_test',
'DBDriver' => 'postgre',
'DBPrefix' => 'db_',
'pConnect' => false,
'DBDebug' => (ENVIRONMENT !== 'production'),
'cacheOn' => false,
'cacheDir' => '',
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
'port' => 5433,
];
我不知道我在做什么错,我知道 .env 文件覆盖了 config\App.php 配置,并给了我错误 CodeIgniter\Database\Exceptions\DatabaseException #8 em> 并显示 throw new DatabaseException('Unable to connect to the database.');
了解更多有关该主题的人可以帮助我,将不胜感激。
【问题讨论】:
-
遇到同样的问题。你解决了吗?
标签: php database postgresql codeigniter codeigniter-4