php - fatal error : Uncaught Error: Call to undefined function pg_connect()

标签 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);

?>

最佳答案

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

关于php - fatal error : Uncaught Error: Call to undefined function pg_connect(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44842054/

相关文章:

php - 如何从数组中的每个对象获取对象属性?

javascript - 如何动态添加选择框,从数据库中检索数据

php - 我无法从 PHP 中的数据库获取存储值(存储值是没有扩展名的文件名)

php - 无法添加 laravel/homestead 盒子。 "SSL certificate prob.."。 window

php - 没有设置 HttpOnly 标志的 session Cookie

facebook - 允许在受密码保护的站点上共享 FB

java - Tomcat:未找到允许使用 OpenSSL 的 native 库

windows - 我可以在 Windows 10 上获取(新的)bash 来加载 .profile

ubuntu - 无法通过公网 IP 访问 EC2 实例

Java servlet 无法识别包