致命错误:调用未定义的函数 pg_connect() [英] Fatal error: Call to undefined function pg_connect()

查看:32
本文介绍了致命错误:调用未定义的函数 pg_connect()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试连接到安装了 PostgreSQL 的数据库(远程服务器).我的 PHP 代码正在尝试使用 pg_connect() 连接到数据库,但我收到错误消息:-致命错误:在第 82 行的/var/www/website/functions.php 中调用未定义的函数 pg_connect()".

I am trying to connect to my database (remote server) which has PostgreSQL installed in it. My PHP code is trying to connect to the database using pg_connect(), but I get the error saying:- "Fatal error: Call to undefined function pg_connect() in /var/www/website/functions.php on line 82".

第 82 行就是:

$db = pg_connect($conn_string);
where $conn_string = "host=".$hostname." port=5432 dbname=".$dbname." user=".$db_user." password=".$db_password.""

(之前定义的所有变量)

(all variables defined earlier)

我检查了许多论坛,建议的唯一解决方案是找到包含一行的 php.ini 文件:- extension = pgsql.so(对于 UNIX)和 extension = php_pgsql.dll(对于 Windows).

I checked many forums and the only solution suggested was locating the php.ini file which contains a line:- extension = pgsql.so (for UNIX) and extension = php_pgsql.dll (for Windows).

这个语句应该被注释掉,解决方法是取消注释.我已经尝试过了,但仍然没有改变这种情况.远程服务器安装了 PostgreSQL v9.0.4 之后的版本.然后我将 PostgreSQL v8.4.8 安装到我的笔记本电脑上,并使用 MAMP 在本地运行该网站.起初,Apache 因某些奇怪的原因崩溃了,我解决了这个问题,但最终还是出现了与以前相同的错误,即致命错误:调用未定义的函数 pg_connect()....

This statement is supposed to be commented and the solution is to uncomment it. I have tried it but still does not change the situation. The remote server has a version later than PostgreSQL v9.0.4 installed. I then installed PostgreSQL v8.4.8 on to my laptop and ran the website locally using MAMP. At first, Apache crashed for some odd reason, I fixed that problem but again I ended up with the same error as before i.e. Fatal error: Call to undefined function pg_connect()....

我还运行了 phpinfo() 并且它显示 php 版本确实支持 PostgreSQL 模块.我花了一整天寻找解决方案但没有成功.这是我第一个开发网站的项目,我已经失去理智了.任何帮助将不胜感激.

I also ran the phpinfo() and it showed that the php version does support the PostgreSQL module.I have spent an entire day searching for the solution but have been unsuccessful. This is my first project developing a website and I am out of wits. Any kinda help will be highly appreciated.

phpinfo() 在终端给了我一大堆东西,但与 PostgreSQL 相关的列表如下:-

phpinfo() gives me a huge list of things at the terminal but the listings relevant to PostgreSQL are as follows:-

pdo_pgsql

PDO Driver for PostgreSQL => enabled
PostgreSQL(libpq) Version => 9.0.4
Module version => 1.0.2
Revision =>  $Id: pdo_pgsql.c 306939 2011-01-01 02:19:59Z felipe $ 

pgsql

PostgreSQL Support => enabled
PostgreSQL(libpq) Version => 9.0.4
Multibyte character support => enabled
SSL support => enabled
Active Persistent Links => 0
Active Links => 0

Directive => Local Value => Master Value
pgsql.allow_persistent => On => On
pgsql.auto_reset_persistent => Off => Off
pgsql.ignore_notice => Off => Off
pgsql.log_notice => Off => Off
pgsql.max_links => Unlimited => Unlimited
pgsql.max_persistent => Unlimited => Unlimited

每次编辑后我都重新启动了 MAMP,因为到目前为止我读过的每篇文章中都提到了它.我相信这会重置 Apache 和 php.

I had restarted MAMP after every edit I made since it was mentioned in every post I have read so far. I believe that resets both Apache and php.

'pqsql.so'(在 UNIX 中相当于 Windows 中的 'php_pqsql.dll')存在于 'extension' 目录中.我还将pqsql.so"文件复制粘贴到 Apache/bin 目录中,但它没有给我任何更改.

'pqsql.so' (which is the UNIX equivalent of 'php_pqsql.dll' in Windows) is present in the 'extension' directory. I also copy-pasted the 'pqsql.so' file on to the Apache/bin directory but it did not give me any change.

我主要不是在命令行中运行 php.我只是想知道 phpinfo() 会给我什么与我在上面的回复中提到的 pgsql 相关的内容.

I am not running php in the command line primarily. I just was curious to see what phpinfo() would give me relevant to pgsql which I have mentioned in my reply above.

我仍在研究您提到的工具,并会在得到任何结果后立即回复.

I am still working on the tools you have mentioned and will respond as soon as I get any results.

谢谢,高

推荐答案

您需要安装 php-pgsql 包或任何为您的平台调用的包.顺便说一下,我认为你不是这么说的.

You need to install the php-pgsql package or whatever it's called for your platform. Which I don't think you said by the way.

在 Ubuntu 和 Debian 上:

On Ubuntu and Debian:

sudo apt-get install php5-pgsql

这篇关于致命错误:调用未定义的函数 pg_connect()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆