Home  >  Article  >  php教程  >  如何将数据从文本导入到mysql_php基础

如何将数据从文本导入到mysql_php基础

WBOY
WBOYOriginal
2016-05-17 09:07:07876browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn