php 把csv文件导入到mysql数据库

作者:袖梨 2022-06-24
 代码如下 复制代码
$fname = $_files['myfile']['name'];
$do = copy($_files['myfile']['tmp_name'],$fname);
if ($do){
echo"导入数据成功
";
}else{
echo "";
}

 

 代码如下 复制代码

error_reporting(0);// 导入csv格式的文件
$connect=mysql_connect("localhost","root","") or die("could not connect to database");
mysql_select_db("gklqtzcx",$connect) or die (mysql_error());
mysql_query("set names 'gbk'");
$fname = $_files['myfile']['name'];
$handle=fopen("$fname","r");
while($data=fgetcsv($handle,10000,",")){
$q="insert into records (name,classes,a_time,college,notify,receiver,r_time,handler) values ('$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]')";
mysql_query($q) or die (mysql_error());
}
fclose($handle);
echo "1秒钟转入列表页,请稍等."

?>

" method="post">

导入cvs数据


相关文章

精彩推荐