Home > Article > Backend Development > php access以汉语言作为参数进行数据查询时出现乱码
php access以中文作为参数进行数据查询时出现乱码。
先上代码:
<?php<br /> <br /> include_once("Conn.php");<br /> <br /> $testJSON=array();<br /> $str = trim($_GET['dept']); <br /> <br /> $mysql =" select *,0 as ord from checkpro where ifstop=0 and dept like '*".$str."*' ";<br /> <br /> echo $mysql; <br /> <br /> $rs = $conn->Execute($mysql);<br /> while(!$rs->EOF) <br /> { <br /> <br /> $mydept =iconv('gb2312','utf-8',$rs->Fields['dept']->Value);<br /> $mypro =iconv('gb2312','utf-8',$rs->Fields['pro']->Value);<br /> $mynote =iconv('gb2312','utf-8',$rs->Fields['note']->Value);<br /> $mykf =iconv('gb2312','utf-8',$rs->Fields['kf']->Value);<br /> <br /> echo $mydept;<br /> <br /> $testJSON[] = array('dept'=>"".$mydept."","pro"=>"".$mypro."","note"=>"".$mynote."","kf"=>"".$mykf.""); <br /> $rs->MoveNext();<br /> }<br /> <br /> foreach ( $testJSON as $key => $value ) { <br /> <br /> foreach ( $testJSON[$key] as $key_k => $value_k ) { <br /> $testJSON[$key][$key_k] = urlencode ($value_k); <br /> }<br /> } <br /> echo urldecode ( json_encode ( $testJSON ) ); <br /> <br /> /*释放资源*/<br /> $rs->Close();<br /> $conn->Close();<br /> $rs = null;<br /> $conn = null;<br /> <br /> ?>