RE: Re: No data?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Wow, this is unbeileivable. Your test script fails with the attached csv where column `a` in blank too!


Php.ini
http://pastie.org/4340845


mysql> select * from `testBook1csv`;
+----+--------+
| id | field0 |
+----+--------+
|  1 | NULL   |
|  2 | NULL   |
|  3 | NULL   |
|  4 | NULL   |
|  5 | NULL   |
|  6 | NULL   |
+----+--------+
6 rows in set (0.00 sec)


*************************output from your script**********************

file upload example

$_FILES

  array(1) {
  ["userfile"]=>
  array(5) {
    ["name"]=>
    string(13) "testBook1.csv"
    ["type"]=>
    string(24) "application/octet-stream"
    ["tmp_name"]=>
    string(14) "/tmp/phphf42G8"
    ["error"]=>
    int(0)
    ["size"]=>
    int(102)
  }
}
ls -l /tmp/phphf42G8

-rw------- 1 apache apache 102 Jul 27 00:17 /tmp/phphf42G8
$sql for create table

string(110) "create table if not exists `testBook1csv` (id integer not null auto_increment primary key, field0 varchar(50))"
$sql for load data

string(142) "load data local infile '/tmp/phphf42G8' into table `testBook1csv` fields terminated by ',' optionally enclosed by '"' lines terminated by '\n'"
Verify data contents

Table testBook1csv

string(28) "select * from `testBook1csv`"
$sql=
data

array(2) {
  [0]=>
  string(1) "1"
  [1]=>
  NULL
}
array(2) {
  [0]=>
  string(1) "2"
  [1]=>
  NULL
}
array(2) {
  [0]=>
  string(1) "3"
  [1]=>
  NULL
}
array(2) {
  [0]=>
  string(1) "4"
  [1]=>
  NULL
}
array(2) {
  [0]=>
  string(1) "5"
  [1]=>
  NULL
}
array(2) {
  [0]=>
  string(1) "6"
  [1]=>
  NULL
}

-----Original Message-----
From: tamouse mailing lists [mailto:tamouse.lists@xxxxxxxxx] 
Sent: Thursday, July 26, 2012 11:39 PM
To: Brad
Cc: jim.giner@xxxxxxxxxxxxxxxxxx; php-db@xxxxxxxxxxxxx
Subject: Re:  Re: No data?

With one change to the data file to make the indexing work correctly and read all the fields: to accommodate the first id auto_increment field, the first value in the csv line must be null:

null.a,b,c,d,e
null,f,g,h,i,j
null,k,l,m,n,o

And further, the field count should subsequently be one less in line
53 when creating the table:

for ($i=0; $i < (count($fields)-1); $i++) {

and that should do it.

On Thu, Jul 26, 2012 at 10:20 PM, tamouse mailing lists <tamouse.lists@xxxxxxxxx> wrote:
> Brad, do take a look at http://pastie.org/4340383 It does work.

Attachment: testBook1.csv
Description: MS-Excel spreadsheet

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux