Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过PHP连接到PostgreSQL_Php_Postgresql - Fatal编程技术网

通过PHP连接到PostgreSQL

通过PHP连接到PostgreSQL,php,postgresql,Php,Postgresql,它只是停留在。。。或者死(“无法连接”);没有其他事情发生,但我知道连接字符串上的一切都是正确的 <?php header('Content-Type: text/html; charset=utf-8'); echo "Teste Inicio"; //To see if it can reach this part of code $conn_string = "host='localhost' port='5432' dbname='name_db' us

它只是停留在。。。或者死(“无法连接”);没有其他事情发生,但我知道连接字符串上的一切都是正确的

<?php
    header('Content-Type: text/html; charset=utf-8');

    echo "Teste Inicio"; //To see if it can reach this part of code

    $conn_string = "host='localhost' port='5432' dbname='name_db' user='user_pgsql' password='passuser_pgsql'"; //Connection String
    $db_conn = pg_connect($conn_string) or die("Can't Connect");

    echo "Teste Depois Conexão"; //To see if it can reach this part of code

    $stat = pg_connection_status($db_conn);
    echo $stat;


    if ($db_conn)
    {
        echo "Teste Conectou"; //Echo to see if it has connected
            $query = "SELECT idgestores FROM gestores"; //Query
            echo "<br>"."Conexão bem sucedida"; //Connection Successfully
            $result = pg_query($db_conn, $query);
            while($row = pg_fetch_row($result))
            {
                echo "<br>"."ID: $row[0]   Nome: $row[1]";
                echo "<br>";         
            }
    }
    else
    {
        echo "Teste Erro"; //Error
        echo "Erro de Ligação"; //Error
    }
?>

尝试重新移动dsn上的简单引号(
$conn\u string
)是否确定
用户\u pgsql
不必使用密码?我删除了简单引号,但仍然没有密码:passuser\u pgsqlTry在PostgreSQL服务器上启用
日志\u连接
,并查看是否有任何内容写入服务器日志。