PHP Fatal error: Call to undefined function pg connect()

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 02:34 판 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)
Call to undefined function pg connect()
installing php-pgsql
php-pgsql 설치

1 문제상황[ | ]

PHP에서 pg_connect 등 pgsql 관련 함수를 사용하면 다음과 같은 오류 메시지가 나온다.

Fatal error: Call to undefined function pg_connect() in /var/www/html/test_pgsql.php on line 2
→ PHP에 pgsql 관련 모듈이 연동되지 않아서 발생하는 문제이다.

2 php-pgsql 설치[ | ]

php-pgsql 모듈이 설치되어 있는지 확인하고, 없다면 설치

2.1 설치 전 확인[ | ]

[root@zetawiki ~]# rpm -qa | grep php-pgsql
[root@zetawiki ~]# yum info php-pgsql
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Available Packages
Name       : php-pgsql
Arch       : x86_64
Version    : 5.3.3
Release    : 3.el6_2.8
Size       : 68 k
Repo       : Daum
Summary    : A PostgreSQL database module for PHP
URL        : http://www.php.net/
License    : PHP
Description: The php-pgsql package includes a dynamic shared object (DSO) that can
           : be compiled in to the Apache Web server to add PostgreSQL database
           : support to PHP. PostgreSQL is an object-relational database management
           : system that supports almost all SQL constructs. PHP is an
           : HTML-embedded scripting language. If you need back-end support for
           : PostgreSQL, you should install this package in addition to the main
           : php package.
→ 설치되지 않았다.

2.2 설치[ | ]

[root@zetawiki ~]# yum install php-pgsql -y
... (생략)
============================================================================================================
 Package                       Arch                 Version                        Repository          Size
============================================================================================================
Installing:
 php-pgsql                     x86_64               5.3.3-3.el6_2.8                Daum                68 k
Installing for dependencies:
 postgresql-libs               x86_64               8.4.11-1.el6_2                 Daum               198 k
Updating for dependencies:
 php                           x86_64               5.3.3-3.el6_2.8                Daum               1.1 M
 php-cli                       x86_64               5.3.3-3.el6_2.8                Daum               2.2 M
 php-common                    x86_64               5.3.3-3.el6_2.8                Daum               522 k
 php-mysql                     x86_64               5.3.3-3.el6_2.8                Daum                79 k
 php-pdo                       x86_64               5.3.3-3.el6_2.8                Daum                73 k

Transaction Summary
============================================================================================================
Install       2 Package(s)
Upgrade       5 Package(s)

Total download size: 4.2 M
Downloading Packages:
(1/7): php-5.3.3-3.el6_2.8.x86_64.rpm                                                | 1.1 MB     00:00     
(2/7): php-cli-5.3.3-3.el6_2.8.x86_64.rpm                                            | 2.2 MB     00:00     
(3/7): php-common-5.3.3-3.el6_2.8.x86_64.rpm                                         | 522 kB     00:00     
(4/7): php-mysql-5.3.3-3.el6_2.8.x86_64.rpm                                          |  79 kB     00:00     
(5/7): php-pdo-5.3.3-3.el6_2.8.x86_64.rpm                                            |  73 kB     00:00     
(6/7): php-pgsql-5.3.3-3.el6_2.8.x86_64.rpm                                          |  68 kB     00:00     
(7/7): postgresql-libs-8.4.11-1.el6_2.x86_64.rpm                                     | 198 kB     00:00     
------------------------------------------------------------------------------------------------------------
Total                                                                       725 kB/s | 4.2 MB     00:05     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating       : php-common-5.3.3-3.el6_2.8.x86_64                                                   1/12 
  Updating       : php-pdo-5.3.3-3.el6_2.8.x86_64                                                      2/12 
  Updating       : php-cli-5.3.3-3.el6_2.8.x86_64                                                      3/12 
  Installing     : postgresql-libs-8.4.11-1.el6_2.x86_64                                               4/12 
  Installing     : php-pgsql-5.3.3-3.el6_2.8.x86_64                                                    5/12 
  Updating       : php-5.3.3-3.el6_2.8.x86_64                                                          6/12 
  Updating       : php-mysql-5.3.3-3.el6_2.8.x86_64                                                    7/12 
  Cleanup        : php-5.3.3-3.el6_1.3.x86_64                                                          8/12 
  Cleanup        : php-mysql-5.3.3-3.el6_1.3.x86_64                                                    9/12 
  Cleanup        : php-pdo-5.3.3-3.el6_1.3.x86_64                                                     10/12 
  Cleanup        : php-cli-5.3.3-3.el6_1.3.x86_64                                                     11/12 
  Cleanup        : php-common-5.3.3-3.el6_1.3.x86_64                                                  12/12 

Installed:
  php-pgsql.x86_64 0:5.3.3-3.el6_2.8                                                                        

Dependency Installed:
  postgresql-libs.x86_64 0:8.4.11-1.el6_2                                                                   

Dependency Updated:
  php.x86_64 0:5.3.3-3.el6_2.8        php-cli.x86_64 0:5.3.3-3.el6_2.8  php-common.x86_64 0:5.3.3-3.el6_2.8 
  php-mysql.x86_64 0:5.3.3-3.el6_2.8  php-pdo.x86_64 0:5.3.3-3.el6_2.8 

Complete!

2.3 설치 후 확인[ | ]

[root@zetawiki ~]# php --ini
Configuration File (php.ini) Path: /etc
Loaded Configuration File:         /etc/php.ini
Scan for additional .ini files in: /etc/php.d
Additional .ini files parsed:      /etc/php.d/curl.ini,
/etc/php.d/fileinfo.ini,
/etc/php.d/json.ini,
/etc/php.d/mysql.ini,
/etc/php.d/mysqli.ini,
/etc/php.d/pdo.ini,
/etc/php.d/pdo_mysql.ini,
/etc/php.d/pdo_pgsql.ini,
/etc/php.d/pdo_sqlite.ini,
/etc/php.d/pgsql.ini,
/etc/php.d/phar.ini,
/etc/php.d/sqlite3.ini,
/etc/php.d/zip.ini
→ php-pgsql 연동 모듈에 관한 설정 /etc/php.d/pdo_pgsql.ini 이 추가되었다.

3 httpd 재시작[ | ]

변경된 설정을 적용하기 위해서는 httpd를 재시작해야 한다.

[root@zetawiki ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
→ 재시작 후 브라우저로 접속해보니 오류가 나지 않는다.

4 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}