0

i have made some custom module that i use for importing csv to database in drupal 7 but i got some error

Notice: Undefined offset: 2 PDOException: SQLSTATE[22021]: Character not in repertoire: 7 ERROR: invalid byte sequence for encoding "UTF8": 0x8d HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding"

here my code

    if(isset($form_state['values']['csvupload'])) {
    if($handle = fopen($form_state['values']['csvupload'],'r')) {
        $btach['operations'][] = array('+importcsv_remember_filename', array($form_state['values']['csvupload']));
        db_set_active('data7');
        $line = fgetcsv($handle,4096);
        while ($line = fgetcsv($handle,4095)) {
            for($i = 0,$j = count($line); $i < $j; $i++) {
                $insert_csv = array();
                $insert_csv['id'] = $line[0];
                $insert_csv['nama'] = $line[1];
                $insert_csv['alamat'] = $line[2];
                $insert_csv['fakultas'] = $line[3];
                $insert_csv['pekerjaan'] = $line[4];
            }
            $i++;
            $nid = db_insert('unikom')
            ->fields(array(
                'id' => $insert_csv['id'],
                'nama' => $insert_csv['nama'],
                'alamat' => $insert_csv['alamat'],
                'fakultas' => $insert_csv['fakultas'],
                'pekerjaan' => $insert_csv['pekerjaan'],
            ))
            ->execute();
            $batch['operations'][] = array('_importcsv_import_line',array(array_map('base64_decode',$line)));
        }
        fclose($handle);
        $nid = drupal_set_message('success');
    }
}
batch_set($batch);
db_set_active();
ipin upin
  • 21
  • 1
  • 10
  • You have to make sure your strings are clean and do not contain weird characters and/or wrong encoding. – COil Mar 03 '17 at 09:02
  • thanks before . but i have fix the problem that i make change format of csv file become csv(delimiter) – ipin upin Mar 03 '17 at 13:26

0 Answers0