Hi, there is error while importing data from CSV file on PHP 5.2. It gives me message:

fgetcsv() expects at most 4 parameters, 5 given
File /Users/alex/Sites/hosts/drupal/sites/default/modules/migrate/plugins/sources/csv.inc, line 129

Here is a code:

while ($row = fgetcsv($this->result, $this->fgetcsv['length'], $this->fgetcsv['delimiter'], $this->fgetcsv['enclosure'], $this->fgetcsv['escape'])) {

I've found that last parameter escape was added only in PHP 5.3. When I remove it, everything works. So, we need some workaround for other PHP versions.

And another minor bug. In the file csv.inc on line 104 you have:

migrate_instrument_stop('MigrateSourceSQL execute');

but I'm sure it must be

migrate_instrument_stop('MigrateSourceCSV execute');

Comments

moshe weitzman’s picture

Status: Active » Fixed

Committed. thanks ... Most functions don't care if you pass extra params. Odd.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

pounard’s picture

From https://github.com/pounard/fat-csv-reader/blob/master/lib/CsvSmoothReade...

  public function __construct($filename, $settings = array()) {
    // ... code removed
    $this->decentFgetcsv = (version_compare(PHP_VERSION, '5.3.0') >= 0);
  }

Later:

    // PHP 5.3 accepts the 'escape' parameters, using it on PHP 5.2 will make
    // the fgetcsv() function throw a warning and not return any array.
    if ($this->decentFgetcsv) {
      $line = fgetcsv($this->handle, $l, $d, $e, $c);
    } else {
      $line = fgetcsv($this->handle, $l, $d, $e);
    }