1

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?

3
  • 3
    And your try ? any code you have done Commented Dec 31, 2013 at 9:27
  • please try while($dat=fread($res)); Commented Dec 31, 2013 at 9:28
  • You can use file(), then loop over the array with lines, trim them and insert them into the database using PDO Commented Dec 31, 2013 at 9:28

1 Answer 1

2
<?php

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

and so on

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.