csv文件或者excel表格导入数据库
时间:2021-07-01 10:21:17
帮助过:2人阅读
<span style="font-size:18px;"><?
PHP
2 //将csv文件导入到数据库
3 //也可以先将excel文件另存为csv文件后,在进行导入
4 include("./conn.php"
);
5 $file = "./stu.csv"
;
6 $stu =
fopen(
$file,‘r‘
);
7 while(!
feof(
$stu)){
8 echo"<pre>"
;
9 $row =
fgets(
$stu);
10 $rs[] =
explode(‘,‘,
$row);
11 }
12
13 foreach(
$rs as $value){
14 $sql = "insert into stu(name,score)values(‘".
$value[0]."‘,‘".
$value[1]."‘)"
;
15 $mq =
mysql_query(
$sql);
16 }
17 if(
$mq){
18 echo "插入成功!"
;
19 }</span>
例如:


csv文件或者excel表格导入数据库
标签: