SitePoint Sponsor

User Tag List

Results 1 to 1 of 1
  1. #1
    SitePoint Member
    Join Date
    Oct 2004
    Location
    AUS
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP script to import csv data into MS SQL Server table

    Hi Fellows,

    Could any person help me with a sample PHP script to import data from csv file into MS SQL Server.

    The file has six columns while the table has eight columns. So, I have to modify the file to include two columns and thier values first, then import the file into SQL Server table.

    Any suggestions please.

    Cheers,
    Justman


    Please see below the issue that I am looking for a solution.


    I have a record form with three text boxes:

    Customer Name: C048468145-2 //substr () from filename without extension
    Customer file: C048468145-2.csv //substr () from filename with extension
    Data File: C:\C048468145-2.csv //filename selected by user

    (Action 1)
    (a) Append extra two column names(Customer Name, Customer File,) to the begining of the column row in the (C:\C048468145-2.csv) file.
    They are extra columns names that are required in the file and I will get the values from two textboxes before insert into a table.

    E.g Original File Content column row = : Item,Product Number,Product Type,Date,Time,Stock Number,Cost GST$
    // 7 columns initially.

    After Appending the extra columns = : Customer Number,Customer File,Item,Product Number,Product Type,Date,Time,Stock Number,Cost GST$
    // 9 columns after append.

    (Action 2)
    (c) Append value (C048468145-2) for Customer Number and (C048468145-2.csv) for Customer File columns for each record and insert the record into Customer_Items table. So, the during the import, the record should kind of take this format:

    Customer Name,Customer File,Item,Product Number,Product Type,Date,Time,Stock Number,Cost GST$
    C048468145-2,C048468145-2.csv,822454396,Local,23- Aug,8:12 AM,822416654,7.25,,
    C048468145-2,C048468145-2.csv,822454396,Local,23-Aug,1:43 PM,822415333,5.36,,
    C048468145-2,C048468145-2.csv,822454396,Local,23-Aug,1:55 PM,822228355,3.47,,
    C048468145-2,C048468145-2.csv,822454396,Local,24-Aug,10:22 AM,822974292,7.17,,
    C048468145-2,C048468145-2.csv,822454396,Local,24-Aug,2:04 PM,822974292,5.18,,
    C048468145-2,C048468145-2.csv,822454396,Local,24-Aug,2:12 PM,822418667,4.16,,
    C048468145-2,C048468145-2.csv,822454396,Local,24-Aug,8:20 PM,822941332,4.17,,
    C048468145-2,C048468145-2.csv,822454396,Local,25-Aug,12:51 PM,822974299,25.18,,
    C048468145-2,C048468145-2.csv,822454396,Local,25-Aug,12:51 PM,822974299,8.17,,

    The comma delimeters separates the columns and Item column can be NULL.
    Last edited by justman; Oct 18, 2004 at 14:43.


Bookmarks

Posting Permissions

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