Re: [PHP] From TXT to a mySQL db



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
.



Relevant Pages

  • Re: DBMS and lisp, etc.
    ... Naively implemented with SQL, again for 10 ... (1 query for the initial orders, 1 query for each order for its ... soon as you upgrade to the SQL database. ... (eq (order-customer orderA) ...
    (comp.lang.lisp)
  • Re: complex filter and calculations in access
    ... switch to SQL view. ... query by switching to datasheet view, ... of your database using the from address in this post. ... pre-op infections yes/no ...
    (microsoft.public.access.queries)
  • Re: A little more meat this week
    ... implementation with a query processor capable of returning a result set ... then we can call it a result bag (SQL ... I'm looking at the data model and not database tools at this ... for a s/w developer and a s/w developer simplifies for the end user). ...
    (comp.databases.pick)
  • Re: complex filter and calculations in access
    ... when using a subquery on the same table as the main query, ... switch to SQL view. ... of your database using the from address in this post. ...
    (microsoft.public.access.queries)
  • Re: A little more meat this week
    ... said data includes lists." ... implementation with a query processor capable of returning a result set ... then we can call it a result bag (SQL ... I'm looking at the data model and not database tools at this ...
    (comp.databases.pick)