Joel James
Joel James

Reputation: 1345

How to read a text file and insert those values into database using php

I have a text file like this names ernakulam.txt which has content like this:

name1
name2
name3
name4
name5

I want to insert this value into my Mysql database table named places. Mysql table has fields like this:

dist_id  |  name
_________|______
         |
         |

In this table field1 (dist_id) should be same for all rows. The dist_id value is 6. How to read those names from text file and insert to Mysql table using php?

Upvotes: 1

Views: 2456

Answers (1)

Microbe
Microbe

Reputation: 465

<?php

$file = '/path/to/ernakulam.txt';
$file_content = file_get_contents($file);
$names = explode("\n", $file_content);

and so on

Upvotes: 2

Related Questions