Home > php教程 > php手册 > php解决数据库乱码问题

php解决数据库乱码问题

WBOY
Release: 2016-06-13 09:53:27
Original
1108 people have browsed it

数据库是用UTF-8的话,你那个文本是使用什么编码呀?

用mb_convert_encoding或iconv来转换一下编码。两个编码要一致才不会出现乱码的。还有就是数据库连接方面,如果你有加了set names应该是全部的连接都要那样去加,要不然,会显示乱码的。

下在的例题如果不进行编码转换就会有问题.

       $fileName = "qtgz/qtgongzi.txt";
              $fContent   =   file($fileName);
              //将当前元素的值付给$a_content   list把数组元素的值付给一些变量
              foreach($fContent   as   $a_content) {
              list($QT_sfz,$QT_xm,$QT_bz,$QT_je) = explode( ",",$a_content);
              if($QT_sfz!= "" and $QT_xm !="" and $QT_bz !="" and $QT_je !=""){
              echo $QT_xm;
              //取得时间插入到数据库中
              $QT_sj = date("Ym");
              $query = "insert into qita(QT_sfz,QT_xm,QT_bz ,QT_je,QT_beizhu,QT_sj) values('$QT_sfz','$QT_xm','$QT_bz','$QT_je','$QT_beizhu','$QT_sj')";
              //echo $query;
                     $rst = $aa->excu($query);

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template