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 [email protected]
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 "
" . ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . " | \n";