PHP - Codeigniter - 连接到 PostgreSQL 失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12211253/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP - Codeigniter - Connecting to a PostgreSQL fails
提问by user1452030
I'm pretty new to CodeIgniter, but I have developed a few working pages in the past. I'm trying to refactor those pages (the old pages are still running in a Linux box on Postgres) and developing them in a Windows box; but I'm stuck with a Postgres database connectivity issue and I'm getting the following error:
我是 CodeIgniter 的新手,但我过去开发了一些工作页面。我正在尝试重构这些页面(旧页面仍在 Postgres 上的 Linux 机器中运行)并在 Windows 机器中开发它们;但我遇到了 Postgres 数据库连接问题,并且出现以下错误:
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: C:\Subayogam_v2.0\Codeigniter\system\database\DB_driver.php
Line Number: 124
发生数据库错误
无法使用提供的设置连接到您的数据库服务器。
文件名:C:\Subaogam_v2.0\Codeigniter\system\database\DB_driver.php
行号:124
I know that this error comes up when the database configuration is missing, but I do have a valid DB configuration at C:\Subayogam_v2.0\Codeigniter\application\config\database.php. Given below is the config file data:
我知道当数据库配置丢失时会出现这个错误,但我在 C:\Subaogam_v2.0\Codeigniter\application\config\database.php 有一个有效的数据库配置。下面给出的是配置文件数据:
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'postgres';
$db['default']['password'] = 'mypassword';
$db['default']['database'] = 'subayogam_v2.0';
$db['default']['dbdriver'] = 'postgre';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = TRUE;
/*$db['default']['cachedir'] = '/var/subayogam_2.0/cache';*/
$db['default']['cachedir'] = 'C:\Subayogam_v2.0\Codeigniter\cache';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
I double checked the cache folder path and also tried a simple PHP page that connects to the same DB to see if the drivers are working, and I'm able to see results from the database. No useful error messages in Apache error log either. I've copy pasted the entire application from the running version and modified the DB file to point to the new database. Nothing else has changed.
我仔细检查了缓存文件夹路径,还尝试了一个简单的 PHP 页面,该页面连接到同一个数据库以查看驱动程序是否正常工作,并且我能够从数据库中看到结果。Apache 错误日志中也没有有用的错误消息。我已经从正在运行的版本中复制粘贴了整个应用程序,并修改了 DB 文件以指向新数据库。其他一切都没有改变。
What could be wrong? Is there any specific log file that can provide me with more information on the error?
可能有什么问题?是否有任何特定的日志文件可以为我提供有关错误的更多信息?
回答by Regican
I've had a similar problem when i first setup codeigniter with postgres. Postgres runs on a different port, so you'll need specify the port in the database configuration as such; 5432 was the default port postgres chose since i already had mysql installed.
当我第一次使用 postgres 设置 codeigniter 时,我遇到了类似的问题。Postgres 在不同的端口上运行,因此您需要在数据库配置中指定端口;5432 是 postgres 选择的默认端口,因为我已经安装了 mysql。
$db['default']['port'] = 5432;