Hello everyone im new with php so i need some help.
I have a .txt with some information, let's say this:
970,3584,D53,20170102,OL7GU9,9607,1AT03U2,A,
970,3588,F7A,20170102,OL7GY6,9607,1AT03U2,A,
Each one of this values i want to insert them into my DB (i already have the connection).
My code so far is this:
$myfile = fopen("crawler.txt", "r") or die("Unable to open file!");
if ($myfile) {
$columns = explode(",", fread($myfile, filesize("crawler.txt")))
}
At this point i have an array like this:
array(8825) { [0]=> string(3) "970" [1]=> string(4) "3584" [2]=> string(3) "D53" [3]=> string(8)
"20170102" [4]=> string(6) "OL7GU9" ....and so goes
How do i do the insert each element in the array to the DB?
My current code:
foreach ($columns as $key => $value) {
$var1= $columns[0];
$var2= $columns[1];
$var3= $columns[2];
$var4= $columns[3];
$var5= $columns[4];
$var6= $columns[5];
$var7= $columns[6];
}