问题
I am using cakephp 2.0 and a wamp server. I have enabled the pdo of postgres in the php and i tried connecting to Postgres. However it still says that there is an error. My login and password is also double confirmed.
Below is codes for the database.php file:
public $default = array(
'datasource' => 'Database/Postgres',
'persistent' => false,
'host' => 'localhost',
'port' => '5432',
'login' => 'postgres',
'password' => 'password',
'database' => 'Test',
'schema' => '',
'prefix' => '',
'encoding' => ''
);
I even tried this:
public $default = array( 'datasource' => 'Database/Postgres', 'persistent' => false, 'host' => 'localhost', 'port' => '5432', 'login' => 'postgres', 'password' => 'password', 'database' => 'Test', 'schema' => 'public', 'prefix' => '', 'encoding' => '' );
My pga_hba.config file is:
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
In the C:\wamp\bin\php\php5.3.9\ext
I have both:
php_pdo_pgsql.dll php_pdo_sqlite.dll
My config Postgres config file is :
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)
I check php info and I still found that that the pgsql was not there. I am using wamp server.
[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
I already did this in my php.ini file:
extension=php_pdo_pgsql.dll extension=php_pdo_sqlite.dll extension=php_pgsql.dll
回答1:
A shot in the dark: Is the name of the database Test
or test
? Unquoted identifiers are cast to lower case in PostgreSQL. The manual about that.
Next shot in the dark: You are connecting to localhost
. This is not a local connection via Unix domain socket. For this to work the database must be set up to listen to TCP/IP connections. So you need in your postgresql.conf
:
listen_addresses = '*'
.. and restart.
Also, your pg_hba.conf
settings need to allow the connection. Could be a problem similar to this one.
Start by reading the chapter Connection Settings in the fine manual.
But I am done guessing now. You need to provide the error message.
回答2:
I have found the answer for my problem This guy is very useful
http://tutology.net/category/mysql/install-postgresql-and-phppgadmin-windows-wamp
Basically i Copied libpq.dll from wamp\bin\php\phpX.X.X to wamp\bin\apache\ApacheX.X.XX\bin
来源:https://stackoverflow.com/questions/9639080/connecting-cakephp-2-0-with-postgresql