Re: Text from Excel csv file loaded into MySQL table
| From: | Richard Lynch | Date: | Mon, 16 Oct 2006 19:54:58 +0000 |
| Subject: | Re: Text from Excel csv file loaded into MySQL table | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-243213@lists.php.net to get a copy of this message | ||
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?