简体   繁体   English

Php连接到postgresql

[英]Php connect to postgresql

$dbconn = pg_connect("host=localhost   dbname=mydbname   user=myuser    password=mypass") or die(pg_last_error());

returns Unable to connect to PostgreSQL server: FATAL: no pg_hba.conf entry for host "::1 ...", 返回Unable to connect to PostgreSQL server: FATAL: no pg_hba.conf entry for host "::1 ...",

What I must do? 我应该做什么?

PS In file php.ini modul extension php_pgsql.dll is enabled PS在文件php.ini modul extension php_pgsql.dll已启用

This or this would've helped you determine the nature of the problem. 将帮助您确定问题的本质。

It looks like you're trying to connect over IPv6 (hence ::1 ) and the host's pg_hba.conf doesn't have a rule allowing you to connect from the IPv6 loopback address ( ::1 ) as user myuser to database mypass . 看起来你正试图通过IPv6连接(因此::1 ),主机的pg_hba.conf没有允许你从用户myuser到数据库mypass的IPv6环回地址( ::1 )连接的规则。

I suspect the server is misconfigured; 我怀疑服务器配置错误; to work around it try specifying the host as 127.0.0.1 (the IPv4 loopback address) instead of localhost , or just omit the host= completely to use unix domain sockets if PHP supports that. 尝试将主机指定为127.0.0.1 (IPv4环回地址)而不是localhost ,或者只是省略host=完全使用unix域套接字(如果PHP支持)。

Your statement "When use mysql (on remote server), as host value we can use host=localhost right?" 您的声明“当使用mysql(在远程服务器上)时,作为主机值,我们可以使用host = localhost吗?” is completely nonsensical for both MySQL and PostgreSQL. 对于MySQL和PostgreSQL来说都是完全没有意义的。 If it's a remote server then it is by definition not on localhost. 如果它是远程服务器,那么根据定义它不在localhost上。 At a wild guess I think you might be trying to say that the server is remote in the sense that it's not the computer you are working on, but it's local to the program you are running because you are running the program on the remote server (by editing it on the remote server, uploading the program text over FTP, or whatever). 我猜想你可能会试图说服务器是远程的,因为它不是你正在使用的计算机,但它是你正在运行的程序的本地服务器,因为你在远程服务器上运行程序(通过在远程服务器上编辑它,通过FTP上传程序文本,或其他任何方式)。

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

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