E
E
Evgeny Komarov2016-11-11 17:41:46
PHP
Evgeny Komarov, 2016-11-11 17:41:46

PHP7 + Oracle - how to set up encoding?

We have ubuntu 16.04 server in stock. Installed instantclient 11.2.0.4.0 (basic, devel and sqlplus) from rpms via alien (installing from zip gives the same result). The environment variables ORACLE_HOME, LD_LIBRARY_PATH and NLS_LANG are registered in both /etc/environment and /etc/profile, the file /etc/profile.d/oracle.sh is also created and imported into ~/.profile. Installed PHP 7.0.8 from the regular repository. The oci8 and pdo_oci extensions have been successfully compiled and included.
The code

try {
    $pdo = new PDO("oci:dbname=DEVELOP", "user", "passwd");
    echo "good connection with PDO";
} catch (Exception $e) {
    echo $e->getMessage();
}

Quietly fulfills, the connection passes.
But as soon as we add an encoding to the DSN, that is, "oci: dbname = DEVELOP; charset = AL32UTF8", we immediately catch an error in the form "OCIEnvNlsCreate: Check the character set is valid and that PHP has access to Oracle libraries and NLS data". At the same time, the connection test through the oci_connect functions of the oci8 library works with a bang, even with encodings specified.
What was done and did not help to overcome the above error:
  • environment variables were written to the php7.0-fpm configuration file
  • environment variables to the fpm-a startup file, as advised here
  • owner /usr/lib/oracle/ set www-data:www-data
  • running php-fpm as root

PS As the tests have shown, it is php-fpm that is to blame for everything, because running the test connection script in the CLI through the banal "php -f ./index.php" gives a positive result.
Need help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pahanium, 2017-05-16
@pahanium

On the old version, I don't remember such a problem, on the new installation, everything is ok in cli, but not in fpm.
I tried everything, then returned everything back, but it helped, as it is written here
in the file /etc/php/5.6/fpm/pool.d/www.conf, to register (replace 12.2 with your version)

env[LD_LIBRARY_PATH] = /usr/lib/oracle/12.2/client64/lib                        
env[ORACLE_HOME] = /usr/lib/oracle/12.2/client64/lib

O
OracleDBA, 2018-02-21
@OracleDBA

The link contains a script to generate the current environment variables for the database.
It also has a good example of an environment file for a database.
dbpilot.net/2018/01/30/generating-an-environment-fi...
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question