将cakephp 2.0与PostgreSQL连接

时间:2012-03-09 18:25:28

标签: php postgresql cakephp cakephp-2.0

我正在使用cakephp 2.0和wamp服务器。我在php中启用了postgres的pdo,我尝试连接到Postgres。但是它仍然说有错误。我的登录名和密码也经过双重确认。

以下是database.php文件的代码:

public $default = array(
  'datasource' => 'Database/Postgres',
  'persistent' => false,
  'host' => 'localhost',
  'port' => '5432',
  'login' => 'postgres',
  'password' => 'password',
  'database' => 'Test',
  'schema' => '',
  'prefix' => '',
  'encoding' => ''
 );

我甚至试过这个:

public $default = array(
    'datasource' => 'Database/Postgres',
    'persistent' => false,
    'host' => 'localhost',
    'port' => '5432',
    'login' => 'postgres',
    'password' => 'password',
    'database' => 'Test',
    'schema' => 'public',
    'prefix' => '',
    'encoding' => ''
  );

我的pga_hba.config文件是:

 TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

# IPv4 local connections:
host    all         all         127.0.0.1/32          md5
# IPv6 local connections:
host    all         all         ::1/128               md5

在C:\ wamp \ bin \ php \ php5.3.9 \ ext

我有两个:

php_pdo_pgsql.dll
php_pdo_sqlite.dll

我的配置Postgres配置文件是:

listen_addresses = '*'      # what IP address(es) to listen on;
                    # comma-separated list of addresses;
                    # defaults to 'localhost', '*' = all
                    # (change requires restart)
port = 5432             # (change requires restart)
max_connections = 100           # (change requires restart)
# Note:  Increasing max_connections costs ~400 bytes of shared memory per 
# connection slot, plus lock space (see max_locks_per_transaction).
#superuser_reserved_connections = 3 # (change requires restart)
#unix_socket_directory = ''     # (change requires restart)
#unix_socket_group = ''         # (change requires restart)
#unix_socket_permissions = 0777     # begin with 0 to use octal notation
                    # (change requires restart)
#bonjour_name = ''          # defaults to the computer name
                    # (change requires restart)

我检查了php信息,我仍然发现pgsql不在那里。我正在使用wamp服务器。

[PostgresSQL]
; Allow or prevent persistent links.
; http://php.net/pgsql.allow-persistent
pgsql.allow_persistent = On

; Detect broken persistent links always with pg_pconnect().
; Auto reset feature requires a little overheads.
; http://php.net/pgsql.auto-reset-persistent
pgsql.auto_reset_persistent = Off

; Maximum number of persistent links.  -1 means no limit.
; http://php.net/pgsql.max-persistent
pgsql.max_persistent = -1

; Maximum number of links (persistent+non persistent).  -1 means no limit.
; http://php.net/pgsql.max-links
pgsql.max_links = -1

; Ignore PostgreSQL backends Notice message or not.
; Notice message logging require a little overheads.
; http://php.net/pgsql.ignore-notice
pgsql.ignore_notice = 0

; Log PostgreSQL backends Noitce message or not.
; Unless pgsql.ignore_notice=0, module cannot log notice message.
; http://php.net/pgsql.log-notice
pgsql.log_notice = 0

我已经在php.ini文件中执行了此操作:

extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
extension=php_pgsql.dll

2 个答案:

答案 0 :(得分:2)

黑暗中的镜头:数据库的名称是Test还是test? PostgreSQL中将不带引号的标识符强制转换为小写。 The manual about that

黑暗中的下一个镜头:您正在连接到localhost。这不是通过Unix域套接字的本地连接。为此,必须将数据库设置为侦听TCP / IP连接。因此,您需要postgresql.conf

listen_addresses = '*'

..然后重启。

此外,您的pg_hba.conf设置需要允许连接。可能是个问题similar to this one 首先阅读精细手册中的Connection Settings章节。

但我现在已经猜到了。您需要提供错误消息。

答案 1 :(得分:1)

我找到了问题的答案这个人非常有用

http://tutology.net/category/mysql/install-postgresql-and-phppgadmin-windows-wamp

基本上我将来自wamp \ bin \ php \ phpX.X.X的libpq.dll复制到wamp \ bin \ apache \ ApacheX.X.XX \ bin