dongxiz5342 2014-12-10 08:06 采纳率: 100%
浏览 113
已采纳

从ISO-8859-2转换为ORACLE char set AL16UTF16

Hello this is a follow up questing from yesterday,

I have a php script that is parsing a website. I am getting strings in UTF-8 now i want to insert those strings into my Oracle database which uses:

NLS_NCHAR_CHARACTERSET = AL16UTF16
NLS_CHARACTERSET = EE8ISO8859P2

I have tried with :

$rep = iconv("UTF-8","AL-16UTF-16",$string);      

// FAILS - produces ?? in database or scripts fails with "wrong charset"

I have also tried with

$rep = iconv("UTF-8","ISO-8859-2",$string);
$rep1 = iconv("UTF-8","AL-16UTF-16",$rep); 

same as above ... fails with ?? in database.

Anyone has any idea what should i try next?

  • 写回答

1条回答 默认 最新

  • dongyilai4214 2014-12-10 11:31
    关注

    The OCI driver implicitly handles charset conversion. When connecting, ensure you set your charset as UTF-8:

    oci_connect($username, $password, $connection_string, 'UTF-8');
    

    This tells OCI to expect you to provide strings in UTF8 format and to provide resultsets in UTF8, converted from the database charset. From the manual (emphasis mine):

    Determines the character set used by the Oracle Client libraries. The character set does not need to match the character set used by the database. If it doesn't match, Oracle will do its best to convert data to and from the database character set. Depending on the character sets this may not give usable results. Conversion also adds some time overhead.

    This means, assuming that the strings you want to input are in UTF8, that you shouldn't need to use iconv() at all. Just let OCI handle that for you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败