PHP查询oracle数据显示乱码问题

1、Linux下   执行前脚本前先执行一下命令
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8"

2、Windows下在代码里添加 putenv("NLS_LANG=AMERICAN_AMERICA.AL32UTF8");
例:
header("content-type:text/html;charset=utf-8");
putenv("NLS_LANG=AMERICAN_AMERICA.AL32UTF8");
$conn = oci_connect('SYSTEM','root','localhost/orcl');
if (!$conn) {
$e = oci_error();
//print htmlentities($e['message']);
//WriteLog("连接Oracle时出错,oci_connect(".$db_user_name.",".$db_pwd.",".$db_host_name.") ".htmlentities($e['message']));
var_dump($e);exit;
}
$result_rows = oci_parse($conn, 'select * from CS'); // 配置SQL语句,执行SQL
$row_count = oci_execute($result_rows, OCI_DEFAULT); // 行数 OCI_DEFAULT表示不要自动commit

$count=[];
while($row = oci_fetch_array($result_rows, OCI_ASSOC)) {
// $fileType = mb_detect_encoding($row['SEX'] , array('UTF-8','GBK','LATIN1','BIG5')) ;
// if( $fileType != 'UTF-8'){
// $row['SEX'] = mb_convert_encoding($row['SEX'] ,'utf-8' , $fileType);
// }

$count[] = $row;
}
var_dump($count);exit;
posted @ 2019-07-24 13:46  阡尘小陌  阅读(955)  评论(0编辑  收藏  举报