无法连接到postgresql

时间:2014-12-23 09:54:12

标签: postgresql

我已经写了以下代码

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
    <head></head>
    <body>
        <?php
            // attempt a connection
            // $conn_string = "host=localhost port=5432 dbname=postgis user=postgres password=1234";
            // $dbh = pg_connect($conn_string);  

            $dbh = pg_connect("host=localhost port=5432 dbname=postgis user=postgres password=1234");

            if (!$dbh) {
                die("Error in connection: " . pg_last_error());
            }

            // execute query
            $sql = "SELECT * FROM assets";
            $result = pg_query($dbh, $sql);

            if (!$result) {
                die("Error in SQL query: " . pg_last_error());
            }

            // iterate over result set
            // print each row
            while ($row = pg_fetch_array($result)) {
                echo ": " . $row[0] . "<br />";
                echo ": " . $row[1] . "<p />";
            }

            // free memory
            pg_free_result($result);

            // close connection
            pg_close($dbh);
        ?>
    </body>
</html>

我已将此newphp.php保存在www文件夹中,当我在localhost(wamp服务器)中运行时,会出现以下错误

Call to undefined function pg_connect() in C:\wamp\www\newphp.php on line 18

1 个答案:

答案 0 :(得分:0)

WAMP没有postgresql服务器或db。

下载具有postgresql服务器WAPP的本地服务器 https://bitnami.com/stack/wapp