0

*First of all don't answer "php.ini >> uncomment extension=pgsql.so and restart httpd". did that millions of times, did not solve my problem.

*Tried hundreds of methods described in different sites including stackoverflow, but unfortunately did not work for me (I am leaning Linux >> noob)

INFO: httpd 2.2.15, php 5.6.26 (remi-php56), CentOS 6.8, postgresql 8.2.9

Error 1:

Fatal error: Call to undefined function mb_convert_encoding() in /var/www/html/bancarella_dev/config.php on line 6

Error 1 was solved by:

yum install php-mbstring
service httpd restart

Error 2:

Fatal error: Call to undefined function pg_connect() in /var/www/html/bancarella_dev/dbconnect.php on line 69

To solve Error 2 I did :

yum install php-pgsql
service httpd restart

But it did not solve the Error 2

To see what extensions are loading, I created a test file "test.php"

Code:

$isPgsql =  extension_loaded('pgsql') ? 'yes':'no';

echo "pgsql loaded: {$isPgsql}" ;

print_r(get_loaded_extensions());

Output of test.php:

pgsql loaded: no

Array
(
    [0] => Core
    [1] => date
    [2] => ereg
    [3] => libxml
    [4] => openssl
    [5] => pcre
    [6] => zlib
    [7] => filter
    [8] => hash
    [9] => Reflection
    [10] => SPL
    [11] => session
    [12] => standard
    [13] => apache2handler
    [14] => bz2
    [15] => calendar
    [16] => ctype
    [17] => curl
    [18] => mbstring
    [19] => fileinfo
    [20] => ftp
    [21] => gettext
    [22] => iconv
    [23] => exif
    [24] => PDO
    [25] => Phar
    [26] => sockets
    [27] => sqlite3
    [28] => tokenizer
    [29] => pdo_pgsql
    [30] => pdo_sqlite
    [31] => json
    [32] => zip
    [33] => mhash
)

SO, mbstring is loaded (that's why error 1 was solved).

From the array you can see that pdo_pgsql is also loaded but pgsql is not.

Why? still getting:

Call to undefined function pg_connect()

Please help.

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
MD TAREQ HASSAN
  • 111
  • 1
  • 5
  • Check if you edited the correct php.ini. you can see the php.ini in use with `phpinfo()`; – Gerald Schneider Oct 14 '16 at 09:07
  • With packaged extension, you NEVER have to change anything in the .ini. Each package provide the /etc/php.d/foo.ini which does its job. Output of "php -v" and "php -m" will help. (also "rpm -Va php\*") – Remi Collet Oct 14 '16 at 13:53
  • BTW, CentOS 6.8 provides postgresql 8.4.20, not 8.2.9 – Remi Collet Oct 14 '16 at 14:08
  • @RemiCollet I am really glad that you mentioned something helpful. I was meant to install latest version of postgresql but unfortunately client forced to install a particular version "8.2.9" (may be because of legacy of their system). Now what to do ? The database is live in client's system, so I can't do anything to postgres. How can I solve it now? – MD TAREQ HASSAN Oct 17 '16 at 00:37
  • Another thing I wanna know is that I asked this question here, is it ok or should I ask this type of question in stackoverflow or unix.stackexchange or dba.stackexchange? – MD TAREQ HASSAN Oct 17 '16 at 00:41
  • @RemiCollet **php -v** : 1. _PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/pgsql.so' - /usr/lib64/php/modules/pgsql.so: undefined symbol: lo_truncate in Unknown on line 0_ 2. _Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/pgsql.so' - /usr/lib64/php/modules/pgsql.so: undefined symbol: lo_truncate in Unknown on line 0_ – MD TAREQ HASSAN Oct 17 '16 at 00:47
  • **php -m** : the same array I mentioned in the question. – MD TAREQ HASSAN Oct 17 '16 at 00:52
  • **rpm -Va php** : does nothing – MD TAREQ HASSAN Oct 17 '16 at 00:54
  • @GeraldSchneider Yes Checked that. **php.ini** is in **"/etc/php.ini"** and phpinfo() shows loaded ini which is same. – MD TAREQ HASSAN Oct 17 '16 at 00:56
  • The error message "undefined symbol: lo_truncate" is clear. This PHP version, and so the pgsql extension, is build against system postgresql 8.4, and won't work with older version. – Remi Collet Oct 17 '16 at 04:51
  • @RemiCollet Thanks a lot. Is it possible to fix this problem somehow, for example downgrading php to 5.3 and then (php.ini) uncommenting : **extension = "/location/of/compatible/pgsql.so"** – MD TAREQ HASSAN Oct 17 '16 at 05:15
  • I don't know where postgresql comes from. but I think the first solution is to rebuild from sources. I rather recommend you to use postgresql 8.4. At least using the client library from 8.4 (libpq, the one used by PHP), and if you think 8.2 is really required, install the server in some other location. – Remi Collet Oct 17 '16 at 05:46
  • @RemiCollet ***I did :*** `yum install php , yum install php-pgsql`. is pgsql.so not compatible with php ? (php56 from your repository). [ May be I have to stick with postgresql 8.2 because of legacy reason ] – MD TAREQ HASSAN Oct 17 '16 at 06:11
  • AS I said, PHP in my repository (and in base repo, or any other 3rd party repository) is build against postgresql 8.4, which is the default version available the base repo. Older version cannot be supported. "pgsql" is of course compatible with PHP, it is not with old libpq from 8.2. More: Postgresql 8.2 is EOL, unmaintained, since Dec 2011. while 8.4 in the repository receive security fix, backported by RH dev. So I heartly recommend you use 8.4 from official CentOS repository. – Remi Collet Oct 17 '16 at 06:27
  • @RemiCollet thanks. Updated PostgreSQL and now working properly. – MD TAREQ HASSAN Oct 28 '16 at 01:31

1 Answers1

1

I updated PostgreSQL (as @RemiCollet suggested) and everything is working properly.

yum install postgresql96*  
service postgresql-9.6 initdb  
chkconfig postgresql-9.6 on  
service postgresql-9.6 start  
MD TAREQ HASSAN
  • 111
  • 1
  • 5