Php 将codeigniter 4与postgres连接时出现问题-codeigniter\Database\Exceptions\DatabaseException#8

Php 将codeigniter 4与postgres连接时出现问题-codeigniter\Database\Exceptions\DatabaseException#8,php,database,postgresql,codeigniter,codeigniter-4,Php,Database,Postgresql,Codeigniter,Codeigniter 4,我想用codeigniter 4和postgresql做一个项目,我已经看过几个例子,我甚至阅读了文档,但它在连接到数据库时仍然显示错误 我的文件.env如下所示: # database.tests.hostname = localhost # database.tests.database = postgres_test # database.tests.username = test # database.tests.password = test123 # database.tests.D

我想用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配置,并给出了错误代码Igniter\Database\Exceptions\DatabaseException#8和show throw new DatabaseException('无法连接到数据库')


如果您对本主题有更多了解,并能为我提供帮助,将不胜感激。

您的.env文件将覆盖config/App.php设置。但是,您正在设置注释项的值

#--------------------------------------------------------------------
# DATABASE
#--------------------------------------------------------------------

# database.default.hostname = localhost
# database.default.database = ci4
# database.default.username = root
# database.default.password = root
# database.default.DBDriver = MySQLi

# database.tests.hostname = localhost
# database.tests.database = ci4
# database.tests.username = root
# database.tests.password = root
# database.tests.DBDriver = MySQLi
所有以#开头的值都会被注释。你需要移除它。但是,正如您所看到的,有两个数据库组。一个用于运行单元测试,另一个用于运行应用程序。默认设置运行您的应用程序。这就是你需要取消注释的地方。像这样:

database.default.hostname = localhost
database.default.database = postgres_test
database.default.username = test
database.default.password = test123
database.default.DBDriver = Postgre
请注意,我写的Postgre是大写的,这就是文档中引用的方式

有关此主题的更多信息,请参见:


您的.env文件将覆盖config/App.php设置。但是,您正在设置注释项的值

#--------------------------------------------------------------------
# DATABASE
#--------------------------------------------------------------------

# database.default.hostname = localhost
# database.default.database = ci4
# database.default.username = root
# database.default.password = root
# database.default.DBDriver = MySQLi

# database.tests.hostname = localhost
# database.tests.database = ci4
# database.tests.username = root
# database.tests.password = root
# database.tests.DBDriver = MySQLi
所有以#开头的值都会被注释。你需要移除它。但是,正如您所看到的,有两个数据库组。一个用于运行单元测试,另一个用于运行应用程序。默认设置运行您的应用程序。这就是你需要取消注释的地方。像这样:

database.default.hostname = localhost
database.default.database = postgres_test
database.default.username = test
database.default.password = test123
database.default.DBDriver = Postgre
请注意,我写的Postgre是大写的,这就是文档中引用的方式

有关此主题的更多信息,请参见:


我使用了codeigniter 4和postgres 10

在php配置中,确保启用pgsql扩展

然后可以使用此.env设置

或者,如果要直接在database.php配置中进行编辑,请将DSN留空


我使用了codeigniter 4和postgres 10

在php配置中,确保启用pgsql扩展

然后可以使用此.env设置

或者,如果要直接在database.php配置中进行编辑,请将DSN留空


我只取消了默认数据库组的注释和设置,并将Postgre部分大写,但它仍将我标记为CodeIgniter\database\Exceptions\DatabaseException#8您能在帖子中添加异常内容吗?还有,你是在用spark运行codeigniter吗?如果是这样,请检查此论坛线程:它向我发送CodeIgniter\Database\Exceptions\DatabaseException#8消息,异常抛出新DatabaseException('无法连接到数据库');我没有使用spark,我应该配置一些spark?你作为服务器运行的是什么?我在本地工作,我尝试在CodeIgniter 3中运行,我得到了一个pg_connect()错误:无法连接到PostgreSQL server:紧急停堆身份验证需要libpq版本10或更高版本,你知道吗?我认为错误来自这里,阅读时我发现我必须更新我的libpq,但我不知道如何做我只取消了默认数据库组的注释和设置,并将Postgre部分大写,但它仍然标记我CodeIgniter\database\Exceptions\DatabaseException\8你能在帖子中添加异常所说的内容吗?还有,你是在用spark运行codeigniter吗?如果是这样,请检查此论坛线程:它向我发送CodeIgniter\Database\Exceptions\DatabaseException#8消息,异常抛出新DatabaseException('无法连接到数据库');我没有使用spark,我应该配置一些spark?你作为服务器运行的是什么?我在本地工作,我尝试在CodeIgniter 3中运行,我得到了一个pg_connect()错误:无法连接到PostgreSQL server:紧急停堆身份验证需要libpq版本10或更高版本,你知道吗?我认为错误来自这里,我发现我必须更新我的libpq,但我不知道怎么做