oracle php-oci8 编码问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13192974/
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-09-19 01:13:15  来源:igfitidea点击:

php-oci8 encoding issue

phporaclecharacter-encodingapache2oci8

提问by Ramazan

Similar questions have been asked, but the regular solutions do not work for me. Probably I am missing something. I am about to loose my mind :(((

有人问过类似的问题,但常规解决方案对我不起作用。可能我错过了一些东西。我快要失去理智了:(((

As you can understand it from the title, I have an oracledatabase with non-ascii content. I want to query/display it with phpusing oci8.

正如您从标题中所理解的那样,我有一个非 ascii 内容的oracle数据库。我想使用oci8php查询/显示它。

First of all, the database is in ISO8859P9, i.e. the query

首先数据库是ISO8859P9的,即查询

select parameter, value from v$nls_parameters where parameter in ('NLS_CHARACTERSET', 'NLS_LANGUAGE', 'NLS_TERRITORY')

returns

回报

NLS_LANGUAGE        AMERICAN
NLS_TERRITORY       AMERICA
NLS_CHARACTERSER    WE8ISO8859P9

So I have set up NLS_LANG variable accordingly, i.e. getenv("NLS_LANG") returns "AMERICAN_AMERICA.WE8ISO8859P9".

所以我相应地设置了 NLS_LANG 变量,即 getenv("NLS_LANG") 返回 "AMERICAN_AMERICA.WE8ISO8859P9"。

I inserted AddDefaultCharset ISO-8859-9to /etc/apache2/conf.d/charset file, and I always included <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-9">in head section of html content of php files. So when I check via firebug, I see that the "Content-Type" header for a response is "text/html; charset=ISO-8859-9".

我插入AddDefaultCharset ISO-8859-9到 /etc/apache2/conf.d/charset 文件中,并且我总是包含<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-9">在 php 文件的 html 内容的 head 部分。因此,当我通过 firebug 检查时,我看到响应的“Content-Type”标头是“text/html; charset=ISO-8859-9”。

Lastly, I have a line as default_charset = "ISO-8859-9"in /etc/php5/apache2/php.ini file, and in the core section of the output phpinfo(), I see that default_charset is ISO-8859-9.

最后,我default_charset = "ISO-8859-9"在 /etc/php5/apache2/php.ini 文件中有一行,在输出 phpinfo() 的核心部分,我看到 default_charset 是 ISO-8859-9。

After all these stuff, when I retrieve a string with a character ?in it and echo it, it is shown as '?'. That is the problem!!! When I query select dump(nameofthatstring, 16)..., I see that its byte value is DD, i.e. correct according to 8859-9.

在所有这些东西之后,当我检索一个包含一个字符的字符串?并回显它时,它显示为“?”。那就是问题所在!!!当我查询时select dump(nameofthatstring, 16)...,我看到它的字节值为DD,即根据8859-9 正确。

I am not sure whether it is relevant but, I will give a final detail: When I enter a character ?in a form and submit it via ajax in GET, it is converted to %FD, i.e. the 8859-9 corresponding value, no problem.

我不确定它是否相关,但我会给出最后的细节:当我?在表单中输入一个字符并通过GET中的ajax提交时,它会转换为%FD,即8859-9对应的值,没问题.

When I urldecode it and echo it, it is again ok, I see ?. But when I have a query with a string containing ?in its where clause (after receiving the ajax request), it returns empty set.

当我对它进行 urldecode 并回显时,它又可以了,我看到?. 但是当我有一个包含?在 where 子句中的字符串的查询时(在收到 ajax 请求后),它返回空集。

However, if I select the rows using CHR(253), the rows are selected correctly, but printing these rows again results in '?' characters.

但是,如果我使用 CHR(253) 选择行,则会正确选择行,但再次打印这些行会导致“?” 人物。

I am really stuck. Any help will be highly appreciated. Thanks in advance.

我真的被困住了。任何帮助将不胜感激。提前致谢。

EDIT:

编辑:

$database = "(DESCRIPTION= (ADDRESS= (PROTOCOL=TCP)(HOST=XXXX)(PORT=1521)) (CONNECT_DATA= (SERVER=dedicated)(SERVICE_NAME=sname)))";

First, I have tried this:

首先,我试过这个:

oci_pconnect($username, $password, $database, "AMERICAN_AMERICA.WE8ISO8859P9");

But it did not solve, so I set NLS_LANG variable and changed to the following:

但是并没有解决,所以我设置了 NLS_LANG 变量并更改为以下内容:

oci_pconnect($username, $password, $database);

Nothing changed...

没有改变...

回答by Nelson

Try connecting like this:

尝试像这样连接:

putenv("NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P9");
$db = "(DESCRIPTION=
     (ADDRESS_LIST=
       (ADDRESS=(PROTOCOL=TCP)
         (HOST=$dbhost)(PORT=$dbport)
       )
     )
       (CONNECT_DATA=(SID=$dbname))
 )";
 $conn = OCILogon($dbuser, $dbpasswd, $db);

Set the variables $db*according to your configuration.

$db*根据您的配置设置变量。

回答by Ben310583

I assume you are in a windows environment.

我假设您在 Windows 环境中。

I had the same issue and I fixed it by
* creating a windows environment variable
NLS_LANG FRENCH_FRANCE.WE8ISO8859P1
* adding these line to my httpd.conf
SetEnv NLS_LANG FRENCH_FRANCE.WE8ISO8859P1

我遇到了同样的问题,我通过
* 创建 Windows 环境变量
NLS_LANG FRENCH_FRANCE.WE8ISO8859P1
* 将这些行添加到我的 httpd.conf
SetEnv NLS_LANG FRENCH_FRANCE.WE8ISO8859P1 来修复它

NB : Replace FRENCH_FRANCE.WE8ISO8859P1 by appropriate value

注意:用适当的值替换 FRENCH_FRANCE.WE8ISO8859P1