...

View Full Version : read data from a text file and insert into db



LJackson
05-26-2011, 05:24 PM
Hi All

I Have a text file which has 1000's lines of data, each line is a new record, and each piece of data is seperated by an '|' i am wondering how i can read this file and insert the data into my db?

any help would be greatly appreciated,
thanks

gvre
05-26-2011, 05:31 PM
<?php
$data = @file("data.txt");
if (is_array($data))
{
// BEGIN TRANSACTION HERE

foreach($data as $d)
{
$row = explode("|", $d);
// BUILD SQL HERE
// EXECUTE SQL
}

// COMMIT TRANSACTION HERE
}

LJackson
05-26-2011, 05:48 PM
nice one mate thank you!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum