This topic is locked

CSV Upload

11/13/2007 11:57:48 PM
PHPRunner General questions
G
guroos author

Searching this forum informs me that there is no way for an admin to import/upload data into an access db from within PHPRunner. When ppl have asked about this the usual answer is search the net & you will find plenty of samples. I am now in my 3rd hour of searching and cannot find anything. Yes there are plenty of hits referring to snippets of code or 3rd party solutions, but nothing that appears to be an answer to a very simple question (I thought).
I would just like to import a csv (via asp or php) that contains records to append to an existing table as a batch process instead of one-at-a-time thru data entry.
Any help or examples would be greatly appreciated.

A
acpan 11/14/2007

Hi, here's what work for me which i made it after trial and error, please try yourself:
To hold the import file, creat a table called phonebook_importfile in mysql with fields: id, userid, filename, date_import.

where userid is to store the person who imports and its' up to you if needed.
Actual data stores in phonebook table with fields: id, name, mobile, category

  1. in phprunner, define View by selecting the SQL from your table at the Datasource page with following SQL:
    select `id`,

    `userid`,

    `filename`,

    `date_import`

    From `phonebook_importfile`
  2. Allow Add permission
  3. Define the field type for filename as:
    a. file/image

    b. pathname: files
  4. In the After Added Event:
    global $conn;
    // Windows pathnames are specified using forward slashes rather than backslashes. If you do use backslashes, you must double them.

    // -- Get current path

    // -- The str_replace, when replacing \, need to put \\
    $temp = getcwd();

    $CSVFile_temp = $temp."/files/".$values["filename"];

    $CSVFile = str_replace("\\", "/" , $CSVFile_temp);
    $param = "LOAD DATA LOCAL INFILE '".$CSVFile."' REPLACE INTO TABLE phonebook ";

    $param .= " FIELDS TERMINATED BY ',' LINES TERMINATED BY '\\r\\n' ";

    $param .= "(name,mobile,category) SET userid = '".$_SESSION["UserID"]."',";

    $param .= " date = NOW(), subscription_state = 1";

    mysql_query($param) or die('Error loading data file. Contact support or try naming your file with at least 3 characters (eg. 123.csv)
    ' . mysql_error());
  5. make sure you have a directory called files at your web folder.
  6. Generate the page & try.
  7. Import the csv files with the format:
    name, tel, category

    name, tel, category

    name, tel, category
    eg.
    Michael, +123456789, friends

    Jimmy, +133456789, friends

    Allan, +4123456789, Company
  8. There is probably a small strange behaviour, if your import file name is 'a.csv'

    it will display error file not found at the user's browser.

    Need to name it as other name than a.csv ( i have no time to verify further).

Admin 11/14/2007

We'll have CSV/Excel import functionality available in the next version (December 2007).

G
guroos author 11/14/2007

acpan, thank you very much for your effort, however I did state that I was using an Access file, not mysql. So not sure whether your solution will work.
Fortunately I am in a position where I can wait for the next version that Admin hopes will be out in December and hopefully will have an import feature.
Once again thanks to you both.

N
nickrix 11/22/2007

Do you think there will be a upload limit to the upload / import .csv function??
I am only asking as i need to find a way to import a huge amount of data each month, i dont know if there will be a way of only importing changed data. for example
if the database has

unique number , co name, phone, address 1 etc like below:
0001, tesco plc, 987654321, tesco house, wc1 3gd
if a month later i had the following in the csv file it would only upload the changed phone number
0001, tesco plc, 123456789, tesco house, wc1 3gd

acpan, thank you very much for your effort, however I did state that I was using an Access file, not mysql. So not sure whether your solution will work.

Fortunately I am in a position where I can wait for the next version that Admin hopes will be out in December and hopefully will have an import feature.
Once again thanks to you both.

A
acpan 11/23/2007

Do you think there will be a upload limit to the upload / import .csv function??
-- I uploaded 12000 records in 2 sec. with a Xeno Single CPU 1Gb RAM.
if the database has

unique number , co name, phone, address 1 etc like below:
0001, tesco plc, 987654321, tesco house, wc1 3gd
if a month later i had the following in the csv file it would only upload the changed phone number
0001, tesco plc, 123456789, tesco house, wc1 3gd
-- It will skip insert for duplicate primary key in DB. So no, it will not update the changes.

N
nicolagrimshaw 12/4/2007

acpan, thank you very much for your effort, however I did state that I was using an Access file, not mysql. So not sure whether your solution will work.

Fortunately I am in a position where I can wait for the next version that Admin hopes will be out in December and hopefully will have an import feature.
Once again thanks to you both.


Hi,
Don't know if you are still looking for an answer? I use Navicat as a workaround; it's a bit longwinded as you have to import the access database then convert to MySQL, dump the file then upload...
There is a 30 day free trial and then I have found they allow an extra 30 days - should see you through until the next release.