1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| try
{
$dbh = new PDO('mysql:host=localhost;dbname=nom_base','user','password');
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
}
catch(PDOException $e)
{
exit($e->getMessage());
}
$file = new SplFileObject($NomDuFichier);
$file->setFlags(SplFileObject::READ_CSV | SplFileObject::SKIP_EMPTY);
$file->setCsvControl(';');
$stmt = $dbh->prepare("INSERT IGNORE INTO ps_import (col1, col2, col3) VALUES (?, ?, ?) ");
foreach($file as $row)
{
$stmt->execute(array($row[0],$row[1],$row[2]));
} |
Partager