I want to import a table from a CSV file into a SQLite DB via a PHP script that I can manually run to update the data.
Heres a list of what I want to achieve:
- Rename old table (which is called "produkte") into product-currentdate (Or drop the table)
- Then import the files from the CSV File (
;separated and ISO 8859-1 charset / The first row of the CSV-file contains the table header) - Save the date in the table "product"
I've found a script which for some reason does not work:
<?php
$dir = 'sqlite:test.sqlite';
$dbh = new PDO($dir) or die("cannot open the database");
$query = <<<eof
LOAD DATA LOCAL INFILE 'produkte.csv'
INTO TABLE produkte
FIELDS TERMINATED BY ';'
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(id, Hauptmenue, Produktgruppe, Beschreibung, Text, Bild, Shop, Info)
eof;
$dbh->query($query);
?>
I hope someone knows how to solve my problem...
Best regards Dave