Re: Text from Excel csv file loaded into MySQL table

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

 



On Mon, October 16, 2006 11:01 am, Alan Milnes wrote:
> Chris Boget wrote:
>>> Can anyone point me to a really good end to
>>> end tutorial on extracting text from an Excel
>>> csv file and uploading it into MySQL via a
>>> PHP script?
>>
>> Actually, depending on the integrity of the data and the consistency
>> of
>> the format in the CSV file, you can do this simply and easily using
>> just
>> MySQL.  Take a look at the following pages:
>>
> Thanks for that.  As there will be a team of people creating the data
> and loading it I need to do some validation etc before it goes into
> the
> database.
>
> Currently I have this and it looks like it might work:-

Ah...

Try something like this:

<?php
  $file = fopen($filename, "r") or die("Could not open $filename");
  while (!feof($file)){
    $values = fgetcsv($file, 1000000);
    array_walk($values, 'mysql_real_escape_string');
    $values_sql = implode("', '", $values);
    $query = "insert into invw2wfinal ";
    $query .= "values('$values') ";
    $result = mysql_query($query) or die(mysql_error());
  }
?>

This assumes that no record (all 4 fields) with overhead is move than
1Mb in size -- Change the 1000000 if you have monster fields.  And
count on needing to tweak my.cnf in that case anyway.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux