Home  >  Article  >  Backend Development  >  How to import data from text to mysql_PHP tutorial

How to import data from text to mysql_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:04:22724browse

In access, you can easily import data in text into tables. In mysql, it is not so convenient, but it is actually very simple.
First process the data records by lines and separate them with specific characters such as: ","
The record format is as follows:
aaa,bbb,ccc,ddd,eee
fff,ggg,hhh,iii ,jjj,kkk
Just create 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<$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!";
?>
Run loaddate.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/316026.htmlTechArticleIn access, you can easily import the data in the text into the table. It is not so convenient to use in mysql. In fact, it is Very simple. First, the data records are processed in rows and separated by specific characters such as...
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