简体   繁体   English

Codeigniter PostgreSQL连接数据库时出错

[英]Codeigniter PostgreSQL error connecting database

I'm used to Codeigniter with mysql(i) but I have a customer who needs PostgreSQL to be connected. 我已经习惯了使用mysql(i)进行Codeigniter,但是我有一个需要PostgreSQL连接的客户。 I tried the usual settings and added the specific port for Postgre but I get this error: 我尝试了常规设置,并为Postgre添加了特定端口,但出现此错误:

Unable to connect to your database server using the provided settings.

在此处输入图片说明

My code is simply this: 我的代码就是这样:

$active_group = (ENVIRONMENT == 'development') ? 'offline' : 'online';
//Set to 'development' in file: index.php    
$active_record = TRUE;

/**
 * OFFLINE CONFIGURATION
 */

$db['offline']['hostname'] = 'localhost';
$db['offline']['username'] = 'root';
$db['offline']['password'] = 'root';
$db['offline']['database'] = 'testing';
$db['offline']['dbdriver'] = 'postgre';
$db['offline']['dbprefix'] = '';
$db['offline']['pconnect'] = TRUE;
$db['offline']['db_debug'] = TRUE;
$db['offline']['cache_on'] = FALSE;
$db['offline']['cachedir'] = '';
$db['offline']['char_set'] = 'utf8';
$db['offline']['dbcollat'] = 'utf8_general_ci';
$db['offline']['swap_pre'] = '';
$db['offline']['autoinit'] = TRUE;
$db['offline']['stricton'] = FALSE;
$db['offline']['port'] = 5432;

/**
 * ONLINE CONFIGURATION
 */
$db['online']['hostname'] = '?';
$db['online']['username'] = '?';
$db['online']['password'] = '?';
$db['online']['database' .... 
//Continues with online configuration...     

Now I'm using the offline configuration for now and this is not working showing the error above. 现在,我现在正在使用offline配置,并且无法正常显示上面的错误。 I did try to set "db_debug" to FALSE and that works but I feel like is just skimping the point and I'll never get database error shown which I need in offline mode... 我确实尝试将“ db_debug”设置为FALSE,并且可以,但是我感觉只是在跳过这一点,而且我永远也不会得到显示脱机模式下所需的数据库错误的信息...

I have pgAdmin open and is connected to the same database and is working ok. 我已打开pgAdmin,并已连接到同一数据库,并且工作正常。 Any hint on this? 有什么暗示吗?

IF there is problem with 如果有问题

$db['offline']['dbdriver'] = 'postgre'

then use 然后使用

$db['offline']['dbdriver'] = 'pdo' 

instead of postgres. 而不是postgres。

According to the documentation page for the CodeIgniter DB drivers, the available values are mysql, postgres, odbc . 根据CodeIgniter DB驱动程序的文档页面 ,可用值为mysql, postgres, odbc So, change the $db['offline']['dbdriver'] value from postgre to postgres and try again. 因此,将$db['offline']['dbdriver']值从postgre更改为postgres然后重试。 It should connect without problems as long as your username and password are right. 只要您的用户名和密码正确,它就可以正常连接。

Edit: There are other sources which suggest that the driver name is actually postgre instead of postgres , contrary to the documentation (that's a shame, really). 编辑:还有其他资料表明,驱动程序名称实际上是postgre而不是postgres ,与文档相反(确实很可惜)。 So I'd suggest that you try with postgres and postgresql . 所以我建议您尝试使用postgrespostgresql If it's still not working, check your php.ini, and check if you have uncommented the PostgreSQL module (search for extension=php_pgsql line). 如果仍然无法正常工作,请检查您的php.ini,并检查您是否已对PostgreSQL模块取消注释(搜索extension=php_pgsql行)。

The module is called php_pgsql.so on Linux boxes, and php_pgsql.dll on Windows. 该模块被称为php_pgsql.so在Linux上盒, php_pgsql.dll在Windows上。

If you see it and it has ; 如果你看到了并且有; before the line, remove the ; 在行之前,删除; and restart the Apache server (it should be available on Windows). 并重新启动Apache服务器(在Windows上应该可用)。 If not, you need to install it first and then add it to php.ini. 如果不是,则需要先安装它,然后将其添加到php.ini中。 The installation varies from distro to distro, but there are plenty of tutorials on how to install it on a Linux box. 不同发行版的安装情况有所不同,但是有很多教程介绍如何在Linux机器上进行安装。

Ok, after looking there was an error in the username. 好的,在查找用户名错误之后。 The configuration was not done by me and the person writing the original username put postres instead of root as was agreed. 配置不是由我完成的,写原始用户名的人按照约定放了postres而不是root

Unfortunately the CI class doesn't output that specific error but just a general "Unable to connect to your database server using the provided settings." 不幸的是,CI类不会输出该特定错误,而只会输出一个常规的“无法使用提供的设置连接到数据库服务器”。

Sorry for the post. 抱歉,该职位。 Thanks to everybody. 感谢大家。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM