Re: From TXT to a mySQL db

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi.

On Thursday 18 October 2007 19:29, Marcelo Wolfgang wrote:
> Hi all,
>
> I need some helps/tips to know if a transition from a txt file to a sql
> database is viable to do.

[snipped data and table descriptions]

> Is there a quick and simple way to convert the row string into a INSERT
> query ?

Once you have opened the file for reading, read one line at a time and use 
explode() to get the individual fields out of each line into an array. By 
the looks of the data you need to tell explode to use ^ as field 
delimiter.

Then contruct an SQL INSERT query and execute it to put the array values 
into the correct table, depending on whether the first value is 10 or 20. 
Make sure you escape each field value to make it safe for whatever 
database you are using.

Repeat for each line until there aren't any more. 

I've done similar things to this more than once and as long as the data 
isn't too weird you should have no problems.

> Should I try some manipulation first with the TXT file ?

I wouldn't imagine there would be any need for that, no. 

Hope this helps,

Mark

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux