【问题标题】:error with "Unable to connect to PostgreSQL server: missing "=" after "0" in connection"“无法连接到 PostgreSQL 服务器:连接中的“0”后缺少“=”错误
【发布时间】:2019-10-30 21:26:45
【问题描述】:

对不起,我是 php 和 postgresql 的新手。 我目前正在尝试连接我的数据库,并且 iv 尝试了两种不同的代码(如下所示),我不确定还能做什么。

$dbservername = "localhost";
$dbusername = "username";
$dbpassword = "password";
$dbname = "abattle";


$db = pg_connect("host="+ $dbservername +
    " dbname=" + $dbname +
    " user=" + $dbusername +
    " password=" + $dbpassword)
    or die('connection failed');
               */


$db = pg_pconnect("dbservername=localhost 
    dbusername=username 
    dbpassword=password dbname=abattle") 
    or die('connection failed');

所以用注释掉的代码,它给出了错误 无法连接到 PostgreSQL 服务器:连接中的“0”后缺少“=”

我得到下面的代码 无效的连接选项“dbservername”(同样适用于 dbusername....)

【问题讨论】:

    标签: php database postgresql connection


    【解决方案1】:

    您与pg_pconnect() 的连接字符串无效。使用类似

    $db = pg_pconnect("host=localhost dbname=abattle user=username password=foo");
    

    查看doc了解更多信息

    【讨论】:

      猜你喜欢
      • 2019-10-08
      • 1970-01-01
      • 2017-04-28
      • 2017-08-16
      • 2023-03-17
      • 1970-01-01
      • 2020-01-24
      • 1970-01-01
      • 2020-12-14
      相关资源
      最近更新 更多