php oracle 查询中文,php操作oracle查询时中文乱码,该怎么处理

当前位置:我的异常网» PHP » php操作oracle查询时中文乱码,该怎么处理

php操作oracle查询时中文乱码,该怎么处理

www.myexceptions.net  网友分享于:2013-08-04  浏览:70次

php操作oracle查询时中文乱码

环境:

oracle数据库是安装在xp上。

版本:10.2.0.3

NLS_LANGUAGE

AMERICAN

NLS_TERRITORY

AMERICA

NLS_CHARACTERSET

ZHS16GBK

一、sqlplus客户端操作数据库(客户端操作语言环境为SIMPLIFIED CHINESE_CHINA.ZHS16GBK):

1、

cmd

set NLS_LANG=American_America.ZHS16GBK

sqlplus /nolog

conn scott/tiger@salesnew

insert into emp values('7777','你','好','7709','1-11月-2012','5000','800','20');

commit;

select * from emp;

EMPNO ENAME JOB MGR HIREDATE SAL COMM

---------- ---------- --------- ---------- ------------ ---------- ----------

DEPTNO

----------

7777 你 好 7709 01-NOV-12 5000 800

20

结论:我录入的数据库是没有问题的。

二、php通过oci操作oracle

1、php所以操作及环境为windows 2003 x86 企业版简体中文+iis6.0+oracle instantclient-basic-win32-10.2.0.4.zip+fcgisetup_1.5_rtw_x86.msi

2、配置完所有必需的环境后,测试了

phpinfo();

?>

显示一切正常

3、开始操作oracle

echo oci_client_version ();

//header('Content-type: text/html; charset=ZHS16GBK');

//set NLS_LANG=American_America.ZHS16GBK

//export NLS_LANG=American_America.ZHS16GBK

//putenv("NLS_LANG=American_America.ZHS16GBK");

$conn = oci_connect('scott', 'tiger', '192.168.1.50/salesnew','ZHS16GBK');

if (!$conn) {

$e = oci_error();

trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);

}

echo oci_server_version ($conn);

// Prepare the statement

$stid = oci_parse($conn, 'SELECT * FROM emp');

if (!$stid) {

$e = oci_error($conn);

trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);

}

// Perform the logic of the query

$r = oci_execute($stid);

if (!$r) {

$e = oci_error($stid);

trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);

}

// Fetch the results of the query

print "

while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {

print "

\n";

foreach ($row as $item) {

print "

" . ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . "\n";

}

print "

\n";

}

print "

\n";

oci_free_statement($stid);

oci_close($conn);

echo "测试页面本身中文显示情况";

?>

中文部分乱码

如下所示:

10.2.0.4.0Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production With the Partitioning, OLAP and Data Mining options

7777 Ä㠺à 7709 01-NOV-12 5000 800 20

8888 ÖÓ º£ 7709 01-NOV-10 5000 800 20

9999 Àî ¾ê 8888 01-JAN-11 3000 5000 20

7369 SMITH CLERK 7902 17-DEC-80 800 20

7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30

7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30

7566 JONES MANAGER 7839 02-APR-81 2975 20

7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30

7698 BLAKE MANAGER 7839 01-MAY-81 2850 30

7782 CLARK MANAGER 7839 09-JUN-81 2450 10

7788 SCOTT ANALYST 7566 19-APR-87 3000 20

7839 KING PRESIDENT 17-NOV-81 5000 10

7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30

7876 ADAMS CLERK 7788 23-MAY-87 1100 20

7900 JAMES CLERK 7698 03-DEC-81 950 30

7902 FORD ANALYST 7566 03-DEC-81 3000 20

7934 MILLER CLERK 7782 23-JAN-82 1300 10

测试页面本身中文显示情况

这一个问题已经折腾我快疯了,百度、谷歌了好几天都解决不了这个问题。

尝试过以下方法

1、设置php环境所在的操作系统环境变量NLS_LAGN=SIMPLIFIED CHINESE_CHINA.ZHS16GBK或NLS_LANG=American_America.ZHS16GBK。

文章评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值