php+oracle 10g乱码问题

来自http://tunps.com/php-with-oracle-10g-unrecognizable-code

最近做毕设,采用php 5.2.x+oracle 10g,php统一采用utf-8字符集,oracle非常菜,在默认安装的情况下字符集是ZHS16GBK,造成php页面输出的数据全部乱码。

google了一下,发现以下方法可行:
oracle采用高级安装:

进入第9步的时候选定AL32UTF8字符集。

本地使用pl/sql developer可能会有乱码,是客户端和服务器端的字符集不一致造成的。修改客户端字符集需要打开注册表:

HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_OraDb10g_home1

将NLS_LANG默认的SIMPLIFIED CHINESE_CHINA.ZHS16GBK

改为

AMERICAN_AMERICA.AL32UTF8或者SIMPLIFIED CHINESE_CHINA.AL32UTF8

——————————————————————————————

update 2010.4.27:

上面的方法比较需要将整个全局的数据库的字符集转移到UTF8,如果其他表空间需要使用其他字符集,那上面的方法就不适用了。除非你新建一个数据库,但是那时比较耗费资源的一种方法。

新方法:

参看php文档里面的oci_connect()函数:

resource oci_connect ( string $username , string $password [, string $db [, string $charset [, int $session_mode ]]] )
 
将charset参数直接改为你php页面的字符集,比如:
$this->conn = oci_connect($user, $passwd, $db,'utf8');
结果一切正常,这样不过你的数据库用的什么字符集,相当于oracle内部的将字符集转到成$charset所对应的字符集。
参考此文
 
 
 
 

About tunpishuang

just 4 fun·····
This entry was posted in 未分类 and tagged , . Bookmark the permalink.

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>