Home >Backend Development >PHP Tutorial >import text to mysql how to import data from text to mysql
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:
aaa,bbb,ccc,ddd,eee
fff,ggg,hhh,iii,jjj,kkk
That's it, create it 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.
The above introduces how to import text into mysql and how to import data from text to mysql, including the content of importing text into mysql. I hope it will be helpful to friends who are interested in PHP tutorials.