CSV Import Standards
Hi there,
Just spent hours trying to move around 2000 records from a database to Pods. Still haven't got it.
I'm getting closer with every try, however now fields with commas are causing records to skip to the next column (eg, when a comma is in the middle of a single-line text field). On Pods 1.11 using Pods API to import. The import package (both 1.0 and 1.1) only spits out errors in the pods functions file.
I've tried enclosing each field with ' or ", however pods just adds those to the field, and continues to skip columns which it encounters a comma.
I tried exporting one of my other pods to examine the generated csv, however some fields are enclosed with " and some aren't - I can't find a pattern. The default csv export from phpMyAdmin encloses everything with this: ";" Perhaps pods could also consider this and escape characters accordingly.
What csv structure does Pods use? The only guidance I have found is "a standard csv file", however there is no standard for csv's...
Thanks,
Harley.
1 Answer
For the timeout, with a large csv file, you will probably have this timeout problem. You can change this in your php.ini by setting a larger value for max_execution_time, or by calling set_time_limit() in your function.
The trim() warnings you are getting may be from empty fields. I don't think these are the root cause of your problem. They are probably getting buffered and displayed when you have the fatal timeout error.
For strings and quotes, the CSV format can be maddening. The semicolon delimiter phpMyAdmin uses isn't much better. What I found worked best was to encode all commas in my data as their ASCII value ,, which keeps them from confusing fgetcsv() during the import. If you can't deal with these characters at runtime, convert them back just before you save using the API call. (The 1.0 version of the plugin does that automatically).
The array() syntax in the import is not part of the CSV standard. I invented that to allow for multi-picks. All I did was embed a php array() statement as part of the CSV data. As the data is parsed, if it finds array, it interprets this as a php array, so it must follow the php syntax rules: "array('one', 2, $data)",
For the format, you are right. There is no standard for it. The function uses fgetcsv() to read the data. Reading through the comments on php.net will give you an idea of its particular quirks.


