php 致命错误:调用未定义的函数 pg_connect

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14849010/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 08:04:35  来源:igfitidea点击:

Fatal error: Call to undefined function pg_connect

phpwindowswamp

提问by Shashidhar Gr

I am using Windows 7, php 5.3.5 and WAMP server. I have two php files: trigger.php and background.php.
I want to run background.php as a background process. I have to call this file from trigger.php. To accomplish this I used below method. I included following code in trigger.php to make background.php to process in background.

我使用的是 Windows 7、php 5.3.5 和 WAMP 服务器。我有两个 php 文件:trigger.php 和 background.php。
我想将 background.php 作为后台进程运行。我必须从 trigger.php 调用这个文件。为了做到这一点,我使用了下面的方法。我在 trigger.php 中包含了以下代码以使 background.php 在后台处理。

$handle = popen('start /b C:\wamp\bin\php\php5.3.5\php.exe     C:\wamp\www\email3.php','r');

in background.php I have the follwing code to connect to database.

在 background.php 我有以下代码连接到数据库。

$conn_string = "host=localhost port=5432 dbname=tagbase user=postgres password=postgres";  

now, on parsing this line am getting the follwing error :

现在,在解析这一行时出现以下错误:

Fatal error: Call to undefined function pg_connect() in C:\wamp\www\background.php on line 3 Call Stack: 0.0002 322792 1. {main}() C:\wamp\www\background.php:0

致命错误:在第 3 行调用 C:\wamp\www\background.php 中未定义的函数 pg_connect() 调用堆栈:0.0002 322792 1. {main}() C:\wamp\www\background.php:0

By searching in in the internet I found some solutions, and made changes as recommended below in php.ini,

通过在互联网上搜索,我找到了一些解决方案,并按照以下建议在 php.ini 中进行了更改,

uncommented, extension=php_pdo_pgsql.dll,
uncommented, extension=php_pgsql.dll,
uncommented, extension_dir = "c:/wamp/bin/php/php5.3.5/ext/",

also I do have php_pdo_pgsql.dll and php_pgsql.dll files in c:/wamp/bin/php/php5.3.5/ext/folder.

我也有 php_pdo_pgsql.dll 和 php_pgsql.dll 文件c:/wamp/bin/php/php5.3.5/ext/夹中的文件。

Any suggestions are appreciated.

任何建议表示赞赏。

回答by Jordi Kroon

Apache 2.2.X configuration

Apache 2.2.X 配置

Add the next line to the Apache 2.2.x httpd.conf configuration:

将下一行添加到 Apache 2.2.x httpd.conf 配置中:

LoadFile "C:/Program Files/PostgreSQL/{version}/bin/libpq.dll"

Above line must be entered before the next line.

上一行必须在下一行之前输入。

LoadModule php5_module "c:/wamp/bin/php/php5.2.11/php5apache2_2.dll"

LoadModule php5_module "c:/wamp/bin/php/php5.2.11/php5apache2_2.dll"

PHP 5.2.X Configuration

PHP 5.2.X 配置

Enable the following two lines in the php.ini configuration file. By 'Enable' i mean, remove trailing ; (semicolon). By these, you un-comment the line.

在 php.ini 配置文件中启用以下两行。“启用”我的意思是,删除尾随 ; (分号)。通过这些,您取消注释该行。

extension=php_pdo_pgsql.dll
extension=php_pgsql.dll

Restart WAMP

重启 WAMP

Test by adding this in your index.php

通过在 index.php 中添加它来测试

echo extension_loaded('pgsql') ? 'yes':'no';

(source: http://www.plaatsoft.nl/wamp-postgresql-integration/)

(来源:http: //www.plaatsoft.nl/wamp-postgresql-integration/

回答by Shashidhar Gr

if we install WAMP server, we will get two php.ini files. one in C:\wamp\bin\php\php5.3.5 and another in C:\wamp\bin\apache\Apache2.2.17\bin.

如果我们安装 WAMP 服务器,我们会得到两个 php.ini 文件。一个在 C:\wamp\bin\php\php5.3.5 中,另一个在 C:\wamp\bin\apache\Apache2.2.17\bin 中。

if we execute a php file from browser, then php.ini file in C:\wamp\bin\apache\Apache2.2.17\bin will be referred. if we execute a php file from command line, then php.ini file in C:\wamp\bin\php\php5.3.5 will be referred.

如果我们从浏览器执行一个 php 文件,那么 C:\wamp\bin\apache\Apache2.2.17\bin 中的 php.ini 文件将被引用。如果我们从命令行执行一个 php 文件,那么 C:\wamp\bin\php\php5.3.5 中的 php.ini 文件将被引用。

what ever the changes i made enable/disable the dll in PHP->PHP extensions,all the changes will be saved in C:\wamp\bin\apache\Apache2.2.17\bin\php.ini file. but C:\wamp\bin\php\php5.3.5\php.ini file remains unchanged.

我所做的任何更改都启用/禁用 PHP->PHP 扩展中的 dll,所有更改都将保存在 C:\wamp\bin\apache\Apache2.2.17\bin\php.ini 文件中。但 C:\wamp\bin\php\php5.3.5\php.ini 文件保持不变。

for my problem, i made the following changes

对于我的问题,我进行了以下更改

uncommented, extension=php_pdo_pgsql.dll,
uncommented, extension=php_pgsql.dll,
uncommented, extension_dir = "c:/wamp/bin/php/php5.3.5/ext/",

in C:\wamp\bin\php\php5.3.5\php.ini file. Now its working good. :)

在 C:\wamp\bin\php\php5.3.5\php.ini 文件中。现在它的工作良好。:)

回答by Jeff_Alieffson

In my case with Apache/2.4.10 PHP Version 5.4.32 PostgeSQL 9.3 I added libpq.dll into Apache httpd.conf from PHP catalog because Apache refused to start with libpq.dll from PostgreSQL 9.3

在我使用 Apache/2.4.10 PHP 版本 5.4.32 PostgeSQL 9.3 的情况下,我从 PHP 目录将 libpq.dll 添加到 Apache httpd.conf 中,因为 Apache 拒绝从 PostgreSQL 9.3 开始使用 libpq.dll