1

I would like to import a csv into a table via Drupal. I use Drupal 7.

I create a content type 'Import', which contains a File field to upload a file to the server (destination: sites / default / files / import / *)

When I validate my form content 'Import', I will wish to make a db_query ()

db_query ("
LOAD DATA INFILE '$ csv_filename' INTO TABLE $ temp_table
FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\"'
LINES TERMINATED BY '\\n'
IGNORE 1 LINES ");

$ csv_filename, I test the relative and absolute way, but drupal tells me it can not find the file. I even give the rights to the file to test 777 but it is not ca.

$ temp_table is my table, it already exists in the database.

You would know the procedure and a use case that works for this query?

1 Answer 1

2

I don't know if this quite what you're looking for, but the Feeds module can import CSV content into nodes. Perhaps it could help...

Import or aggregate data as nodes, users, taxonomy terms or simple database records.

  • One-off imports and periodic aggregation of content
  • Import or aggregate RSS/Atom feeds
  • Import or aggregate CSV files
  • Import or aggregate OPML files
  • PubSubHubbub support
  • Create nodes, users, taxonomy terms or simple database records from import
  • Extensible to import any other kind of content
  • Granular mapping of input elements to Drupal content elements
  • Exportable configurations
  • Batched import for large files
1
  • Thank you for the info. Made in, I had to matter *. Csv file that I sort to update the nodes. I go through reading the file and adding line by line.
    – Djik
    Commented Jun 11, 2014 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.