problem when changing PHP environment variable

Asked

Viewed 657 times

1

I installed php via xampp and need to change this variable:

inserir a descrição da imagem aqui

NSL_LANG.

I created a php file with this code:

<?php 

putenv("NLS_LANG=BRAZILIAN PORTUGUESE_BRAZIL.WE8MSWIN1252") or die("Falha ao inserir a variavel de ambiente");

phpinfo();

?>

but when I open this page it shows as in the image.

I need to change this environment variable to the one of the function. Does anyone know how to do this?

1 answer

1


I believe that by the time of execution this will not work, this because when it executes the putenv the Oracle client is already running, and if I am not mistaken, the communication of PHP with the Oracle client is "parallel" and not in the same "context", ie use putenv will not affect the oracle client process.

What you can do is add manually, in windows do this:

Computer > Estates > Advanced system settings

A window similar to this will appear:

propriedades do sistema

Then click on Environment variables and then in New..., thus:

nova variavel de ambiente

If using the oracle client on more than one user use variaveis de sistema (is preferred), if using only on the current user and you really want to restrict to this then select the "new" from the "User variables to ".

In the variable name field add NLS_LANG In the variable value field add BRAZILIAN PORTUGUESE_BRAZIL.WE8MSWIN1252

After this you may need to log out or even restart Windows.


Using Apache and PHP

Note that apply NLS_LANG=BRAZILIAN PORTUGUESE_BRAZIL.WE8MSWIN1252 will only affect the oracle client, this will not affect the PHP database Apis or Apache, because the apache charset as well as the INPUT coming from Forms or even how you saved the scripts .php may be in a different encoding.

The BRAZILIAN PORTUGUESE_BRAZIL.WE8MSWIN1252 is equivalent to windows-1252, which is equivalent to iso-8859-1, and as I explained in this reply /a/43205/3635 you must use:

  • PHP scripts saved in "iso-8859-1" (or windows-1252 and ANSI)
  • Preferably define using PHP header('Content-type: text/html; charset=iso-8859-1');

First you must save "all . php scripts" as iso-8859-1 (or ANSI) and . html documents (if any):

  • To save using Notepad++:

    salvando documento em ANSI com notepad++

  • To save using Sublimetext:

    salvando documento em iso-8859-1 ou windows 1252

Note: I believe that is not necessary define in the oci_connect the charset, as it already assumes the charset defined in NSLANG, but chance doesn’t work try so:

$db = ocilogon($user, $pass, $connectString, 'WE8MSWIN1252');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.