0
我已經寫了下面的代碼無法連接到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>
我在www
文件夾中保存這爲newphp.php
,當我運行這在我的localhost
(WAMP服務器)出現以下錯誤
Call to undefined function pg_connect() in C:\wamp\www\newphp.php on line 18
您是否安裝了庫? –
正如Marco所說,你錯過了PHP的ps postgreql插件(庫),或者你還沒有在PHP配置中啓用它。 – Jasen
刪除php.ini中'extension = php_pgsql.dll'行之前的註釋,然後重新啓動你的網絡服務器 – vaso123