Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,093
    Thanks
    297
    Thanked 12 Times in 12 Posts

    Post read data from a text file and insert into db

    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

  • #2
    Regular Coder
    Join Date
    May 2011
    Posts
    240
    Thanks
    1
    Thanked 56 Times in 55 Posts
    PHP Code:
    <?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
    }

  • Users who have thanked gvre for this post:

    LJackson (05-26-2011)

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,093
    Thanks
    297
    Thanked 12 Times in 12 Posts
    nice one mate thank you!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •