douba4275 2017-01-13 20:23
浏览 289
已采纳

PHP ODBC连接到Oracle,没有UTF-8

I am having a problem to get UTF-8 support, when i try to connect to Oracle throught ODBC Data Source with PHP odbc_connect().

Also all of this is being done under 32bits. I am using oracle XE DB for testing and instaclient11_2 32bit drivers, ODBC Data source 32it +placed on WAMP32bit server.

Althougt i have same result with Oracle 12c DB and client Home 10g 32bit drivers.

@TODAY Tested this all with 64bit instanclient drivers, added ODBC 64DataSource on 64bit WAMP Server. Still no luck to display chars corretly...

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>

<?php
$connect = odbc_connect("XEXDB", "username", "password");

$query = "SELECT col, 'čaļi' FROM TESST";

$result = odbc_exec($connect, $query);

while(odbc_fetch_row($result)){
  $name = odbc_result($result, 1);
  $surname = odbc_result($result, 2);
  echo "$name, $surname <br/>";
}

odbc_close($connect);

?>

Result i get from this code:

?A?IS, A?aA?i 
Gunt?rs Salts, A?aA?i 

But should be:

ĶAĶIS, čaļi
Guntārs Šalts, čaļi

I cant find how to write $dsn for odbc_connect() to force charset=utf-8, so far no luck to get working $conn_string with charset=utf-8.

Also tried to use utf8_encode() and utf8_decode()(using this was me being desperate).

Does anyone have had similar problem, or maybe someone have some suggestions i could try?

  • 写回答

1条回答 默认 最新

  • doutangu4671 2017-01-24 13:27
    关注

    I found out, that return of ODBC and even ADO connections to ORACLE DB had same returns of ??? instead of UNICODE chars.

    To fix this, I had to add NLS_LANG string value with your DB charset in WINDOWS REGISTRY under 32 un 64 bit location for ORACLE key.

    HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE             --64 bits
    HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\ORACLE --32 bits
    

    and for STRING VALUE(REG_SZ) and VALUE in my case:

    "NLS_LANG"="LATVIAN_LATVIA.BLT8MSWIN1257" 
    

    And for complete picture if someone still didn't get it, I added dump of reg file:

    [HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE]
    @=""
    "NLS_LANG"="LATVIAN_LATVIA.BLT8MSWIN1257"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波