php实现文本数据导入SQL SERVER,
程序员文章站
2022-04-21 13:53:59
...
php实现文本数据导入SQL SERVER,
我测试是支持的CSV,SQL,TXT
其实其他格式也可以,只不过我用不到而已
速度是差不多是每秒一万吧
"; ?> $val) { if(is_array($val)) { $data[$key] = array_iconv($val, $input, $output); } else { $data[$key] = mb_convert_encoding($data, $output, $encoded); } } return $data; } } function microtime_float(){ return microtime(true); } if ($_SESSION['id']''){ if (@$_POST["submit"]""){ if ((($_FILES["file"]["type"] == "text/plain") || ($_FILES["file"]["type"] == "application/vnd.ms-excel") || ($_FILES["file"]["type"] == "application/octet-stream") || ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) && ($_FILES["file"]["size"] 0) { echo "Return Code: " . $_FILES["file"]["error"] . "
"; } else { $name=$_FILES["file"]["name"]; $name=iconv('utf-8', 'GB2312//IGNORE', $_FILES['file']['name']); echo "Upload: " . $_FILES["file"]["name"] . "
"; echo "Size: " . ($_FILES["file"]["size"] / 1048576) . " Mb
"; $exit= pathinfo($_FILES["file"]["name"], PATHINFO_EXTENSION); $exit='.' .$exit; if ($exit==".asp" or $exit==".php" or $exit==".jsp" OR $exit==".aspx"){ echo "我擦,你想做什么?"; exit; } $size=filesize($_FILES["file"]["tmp_name"]); $_FILES["file"]["name"]=md5($_FILES["file"]["name"].$size).$exit; if (file_exists("uploadhehe/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " 已经存在 "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "uploadhehe/" . $_FILES["file"]["name"]); echo "
开始自动处理文件
"; $begin = microtime_float(); $file="uploadhehe/" . $_FILES["file"]["name"]; $handle = @fopen($file, "r"); //$handle=array_iconv('utf-8','gbk',$handle); $total=0; $over=0; if ($handle) { $sql="INSERT INTO [dbo].[own_user_data1] ([Name],[Context],[md5],[data]) VALUES"; $num=0; $_FILES['file']['name']=iconv('utf-8', 'GB2312//IGNORE', $_FILES['file']['name']); while (!feof($handle)) { $buffer = fgets($handle, 2000); $buffer=str_replace("\n", "", $buffer); $line_array=explode("\r\n", $buffer); $Context=htmlspecialchars(addslashes($line_array[0])); $Context=str_replace("'", ',', $Context); $Context=str_replace('"', ',', $Context); $Context=array_iconv($Context); $date=date('y-m-d h:i:s',time()); if($num
以上所述就是本文的全部内容了,希望大家能够喜欢。