-- https://dev.mysql.com/doc/refman/8.0/en/charset-database.html show variables like "character_set_%"; CREATE DATABASE `geovindu` CHARACTER SET utf8 COLLATE utf8_general_ci; -- mysql官方说明文档才知道原来MySQL8.0已经已经把默认字符集升级成ut8mb4了,和5.0有区别 ALTER DATABASE geovindu DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci ; SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'geovindu'; USE geovindu; SELECT @@character_set_database, @@collation_database;
用TXT文件编码UTF-8,导入UTF-8数据库,但当UTF-8网页,输入编号时,查询不到,数据库内有显示. 而TXT文件在简体中文win操作系统, 文件编码ASNI,简体中文直接导入(不转码),会成乱码,在简体中文WIN操作系统UTF-8查询正常.
折腾了两天.解决了.
//上传excel 记事文本 txt 文件编码utf-8 不用转码,但查询,从键盘输入查询不了,只能从数据库存储的编号复制查询可以,虽然看起来显示一样的编号,但就是查询不了 mb_detect_encoding // 记事本TXT 简体中文操作系统下,文件编码ANSI,需要转码,可以查询 function doGeovinDuUptxt(){ import('ORG.Net.UploadFile'); $upload = new UploadFile();// 实例化上传类 $upload->maxSize = 3145728 ;// 设置附件上传大小 $upload->allowExts = array('txt');// 设置附件上传类型 txt 文本类型 $upload->savePath = './uploads/xls/';// 设置附件上传目录 $upload->saveRule = time().'_'.mt_rand(100,999);//设置上传文件规则 if(!$upload->upload()) {// 上传错误提示错误信息 $this->error($upload->getErrorMsg()); $resp=array("stats"=>"error","msg"=>'上传失败!'); echo json_encode($resp); exit; }else{// 上传成功 $uploadList = $upload->getUploadFileInfo();//获取上传成功信息 require_once './data/PHPExcel2/Classes/PHPExcel.php'; define('WWW_PATH',str_replace('\\','/',realpath(dirname(__FILE__).'/../'.'/../'.'/../'.'/../'))); $filePath =WWW_PATH.'/uploads/xls/'.$uploadList[0]['savename']; //快递类型 9f_scanorder $db_scan=M('duscanorder'); $fp_in = fopen($filePath, "r"); while (!feof($fp_in)) { $line = fgets($fp_in); $geovindu=explode('#', $line);//如果有分割 //$data['code']=trim($line); //iconv('utf-8','gb2312', $val) $data['code']= iconv('GB2312', 'UTF-8', trim($geovindu[0]));//trim($geovindu[0]);//TXT文件编码是UTF-8 直接用这个,数据库存储编号是一样,就是查询不了 $data['cnname']=iconv('GB2312', 'UTF-8',trim($geovindu[1])); //trim($geovindu[1]);// iconv('utf-8','gb2312',trim($geovindu[1])); //中文 $data['enname']=iconv('GB2312', 'UTF-8',trim($geovindu[2]));//trim($geovindu[2]);// $db_scan->add($data); //添加至数据库 iconv('GB2312', 'UTF-8', $str); } } $this->msg('导入成功!',U('index')); // showMsg('上传成功!'); }
标签:trim,UTF,5.6,查询,upload,geovindu,乱码,php,上传 From: https://www.cnblogs.com/geovindu/p/17368298.html