如何将数据从文本导入到mysql
如何将数据从文本导入到mysql,如何将数据从文本导入到mysql
首先将数据记录按行处理好用特定的字符分开如:“,”
记录形如:
aaa,bbb,ccc,ddd,eee
fff,ggg,hhh,iii,jjj,kkk
就行,建立loaddate.php
<?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<$n;$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.