致命错误:未捕获错误:调用未定义函数pg_connect()

时间:2017-06-30 08:31:28

标签: php apache ubuntu

从ubuntu服务器调用我的php脚本时出现此错误。我使用apt get安装了php5-pgsql,但错误仍然存​​在。以下是我的源代码,请提供帮助。

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

$host = "localhost";
$port = "5432";
$user = "postgres";
$pass = "root";
$db = "quickbed";

$con = pg_connect("host=$host port=$port dbname=$db user=$user password=$pass") or die ("Could not connect to server\n");

$query = "select * from tbl_hosts, (select count(*) from tbl_hosts) as cnt order by registration_time";
$rs = pg_query($con, $query) or die("Cannot execute query: $query\n");

$rows['spaces']  = pg_fetch_all($rs);

echo json_encode($rows);
pg_close($con);

?>

1 个答案:

答案 0 :(得分:2)

您必须安装PostgreSQL模块并启用它。 http://php.net/manual/en/pgsql.installation.php