Hi All,
I want to take some data from a file (txt) and insert it into a database.
I have a rough idea how to open, read and get the contents of a basic comma delimited file, but I want to be able to read say 5 columns of data from one row and insert into 5 columns in the DB, then the same for the next row etc...
Each row should have the same number of columns, but the rows may vary.
EG
Name, value1, value2, value3
Name, value1, value2, value3
Can anybody give me a hand with this?
Many thanks,
Paul
Reading file contents to database
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
pretty simple stuff on how to build your contents of the file into an array.
Now you have to build your query in a loop.
Code: Select all
//each line of the file is no an array
$lines = file('somefile.txt');
foreach ($lines as $new_line)
{
//arr[0] first column
//arr[1] second column
//etc
$arr = explode(',',$new_line);
}