dqzuo0327 2014-07-18 14:46
浏览 85

PHP连接到Postgre SQL错误

I've never connected to a PostgreSQL database before, so this is all new territory. I'm creating an intranet version of a desktop application that we had created for us in our office. I currently have the desktop application installed and it connects to the PostgreSQL database (on a network server) without any hiccups. I've installed the PostgreSQL odbc drivers and when I use ODBC Data Source Administrator in the Control Panel to test the connection, I get a successful test connection. My issue is when I try to connect directly via a PHP script using all of the same information. I get this error:

Warning: odbc_connect(): SQL error: FATAL: no pg_hba.conf entry for host "10.0.1.218", user "", database "", SSL off, SQL state 28000 in SQLConnect

I understand that I could go to the server and change the connection settings (that's if IT allows me to make changes to the server's files... Not counting on that one).

My setup is: Windows XP, XAMPP v. 1.8.2, PHP 5.4, Postgre SQL drivers 9.03.03. My connection information via ODBC Data Source Administrator is:

Data Source - PostgreSQL
Database - db
Server - 10.0.0.149
User Name - user
SSL Mode - require
Port - 5432
Password - password
Driver - PostgreSQL Unicode

The connection string from the desktop application is:

sDeeperConnection = "Server=10.0.0.149;Database=db;User Id=user;Password=password;SSL=true;Pooling=false";

The connection string that I've created in PHP is:

$dsn='10.0.0.149';
$username='user';
$password='password';
$dbname='db';

$odb = odbc_connect("Driver={PostgreSQL Unicode};Server=$dsn;SSL=true;Pooling=false;Port=5432;Database=$dbname;", $username, $password);

I did notice that the error when I run the PHP script says that SSL 'off' even though I've set it to true, but I don't know how to change this. I've tried 'require' like in the ODBC Data Source Administrator but to no avail. To me it seems that the error (other than the SSL issue) doesn't make sense. I can connect to the PostgreSQL database two different ways on my computer: the desktop application and the ODBC Data Source Administrator. So the issue with there not being an entry for host '10.0.1.218', should be a non-issue in my mind. I've also tried changing the driver I use from PostgreSQL Unicode to PostgreSQL ANSI, but that was also unsuccessful.

I've tried using the pg_connect() function with the same connection parameters after removing the ; from these lines php.ini:

;extension=php_pdo_pgsql.dll
;extension=php_pgsql.dll

But I received the same error. I think it has something to do with the SSL, but I have no idea where to start in testing/debugging the connection using SSL. This problem is a little more difficult due to the fact that I don't have access to the server and getting access to change the files would be like pulling nails.

Any ideas or other options would be great! Thanks ahead of time!

EDIT Looking in my phpinfo this is what I see:

pgsql
PostgreSQL Support  enabled
PostgreSQL(libpq) Version   8.3.3
PostgreSQL(libpq)   PostgreSQL 8.3.3, compiled by Visual C++ build 1500
Multibyte character support     enabled
SSL support     enabled
Active Persistent Links     0
Active Links    0 

openssl
OpenSSL support     enabled
OpenSSL Library Version     OpenSSL 0.9.8y 5 Feb 2013
OpenSSL Header Version  OpenSSL 0.9.8y 5 Feb 2013 

EDIT AGAIN

I downloaded pgAdmin III according to the comments below and setup the connection and I'm connecting just fine. So I know that it's not the host. It's something with the SSL setup, I guess. I just have no idea why/how.... Argh...

  • 写回答

1条回答 默认 最新

  • dongyue7796 2014-07-25 20:24
    关注

    After doing much more digging and reading a ton of solutions for similar but different problems, I ran across a suggestion that someone made to copy the libpq.dll from my c:\xampp\php folder to my C:\xampp\apache\bin folder. I had to overwrite the existing libpq.dll file in that directory. Then I got another error:

    pg_connect(): Unable to connect to PostgreSQL server: FATAL: password authentication failed for user
    

    After doing more reading of random issues someone else had an issue that regardless of the password used or not used, the connection would be created. So, I decided to take out the password in the connection string and it worked! Thanks to all those who commented and kept me looking for a solution!

    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录