Re: Parsing CSV files into a MySQL Table

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

 



> //<?php
> 
> mysql_connect (localhost, foouser, foologin);
> 
> mysql_select_db (footest1);
> 
> $csvfile = file("http://foo.com/foolist.csv";);
> 
> foreach($csvfile as $line_no => $datastring) {
>         $data = explode (",", $datastring);
>         $foo1 = $data[0];
>         $foo2 = $data[1];
>         $foo3 = $data[2];
>         $foo4 = $data[3];
>         $foo5 = $data[4];
>         $foo6 = $data[5];
>         $foo7 = $data[6];
> 
>         mysql_query ("INSERT INTO 'footable' (foo1, foo2, foo3, foo4, foo5, foo6, foo7)
>                 VALUES '$foo1', '$foo2', '$foo3', '$foo4', '$foo5', '$foo6', '$foo7')");
> }
> 
> //?>

try this

mysql_connect (localhost, foouser, foologin);

mysql_select_db (footest1);

$csvfile = file("http://foo.com/foolist.csv";);

while (($data = fgetcsv($csvfile, 1000, ",")) !== FALSE) {
       $foo1 = $data[0];
       $foo2 = $data[1];
       $foo3 = $data[2];
       $foo4 = $data[3];
       $foo5 = $data[4];
       $foo6 = $data[5];
       $foo7 = $data[6];

       mysql_query ("INSERT INTO 'footable' (foo1, foo2, foo3, foo4,
foo5, foo6, foo7)
               VALUES '$foo1', '$foo2', '$foo3', '$foo4', '$foo5',
'$foo6', '$foo7')");
}

-- 
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