Reading CSV data into a database
| From: | Ben Cairns | Date: | Fri, 02 Feb 2001 17:00:44 +0000 |
| Subject: | Reading CSV data into a database | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-5353@lists.php.net to get a copy of this message | ||
I have this script:
<?
$row = 1;
$fp = fopen ("test.txt","r");
while ($data = fgetcsv ($fp, 1000, "\t")) {
$num = count ($data);
$row++;
for ($c=0; $c<$num; $c++) {
print $data[$c] . "<br>";
}
}
fclose ($fp);
?>
It reads a csv file (actually its tab seperated) into an array called $data.
When I call this in my browser, this is fine. But what I need to do is to
put this information into a MySQL database...
The file contains these fields:
region
event_type
event_date
title
info
times
venue
price
event_id (this is auto_incrementing)
How do I read this file into the database?
Any help appreciated, as I have RTFM but I still no idea......