如何将数据从文本导入到mysql
程序员文章站
2022-04-04 13:05:21
...
access中可以将文本中的数据轻松导入表中,MySQL中用起来没那么方便,其实起来也很简单。
首先将数据记录按行处理好用特定的字符分开如:“,”
记录形如:
aaa,bbb,ccc,ddd,eee
fff,ggg,hhh,iii,jjj,kkk
就行,建立loaddate.php
$hostname="localhost";
$username="yourname";
$passWord="yourpwd";
$dbname="yourdb";
mysql_connect($hostname,$username,$password);
mysql_select_db("$dbname");
$mydate=file("yourdate.txt");
$n=count($mydate);
for($i=0;$i $date=explode(",",$mydate[$i]);
$str="insert into ip values('$date[0]','$date[1]','$date[2]','$date[3]','$date[4]')";//
mysql_query($str);
}
mysql_close();
echo "ok!";
?>
运行loaddate.
首先将数据记录按行处理好用特定的字符分开如:“,”
记录形如:
aaa,bbb,ccc,ddd,eee
fff,ggg,hhh,iii,jjj,kkk
就行,建立loaddate.php
$hostname="localhost";
$username="yourname";
$passWord="yourpwd";
$dbname="yourdb";
mysql_connect($hostname,$username,$password);
mysql_select_db("$dbname");
$mydate=file("yourdate.txt");
$n=count($mydate);
for($i=0;$i $date=explode(",",$mydate[$i]);
$str="insert into ip values('$date[0]','$date[1]','$date[2]','$date[3]','$date[4]')";//
mysql_query($str);
}
mysql_close();
echo "ok!";
?>
运行loaddate.