1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
<?php
// including the config file
include('config.php');
$pdo = connect();
$time = date("Y-m-d H:i:s");
$csv_file = $_FILES['csv_file']['tmp_name'];
if (is_file($csv_file)) {
$input = fopen($csv_file, 'a+');
// if the csv file contain the table header leave this line
$row = fgetcsv($input, 1024, ';'); // here you got the header
while ($row = fgetcsv($input, 1024, ';')) {
// insert into the database
$sql = 'INSERT INTO crma_craftman(siret, identification, legal_form, commercial_name, ape_code, synthesis, slug, updated_at, custom_activity ) VALUES(:siret, :raison_sociale, :forme_juridique, :nom_commerciale, :code_ape, :libelledeux, :enseigne, :aujourdhui, :libelleun );
INSERT INTO crma_adress(street1, street2, zip_code, city, canton, phonr_number, email) VALUES ( :voie, :complement, :codepostale, :commune, :canto, :telephone :email);';
// $sqltrois = 'INSERT INTO `crma_actor` (`id`, `craftman_id`, `name`, `type1`, `type2`, `role`) VALUES (NULL, '', '', NULL, NULL, 'G')'; joindre id de actor à id de craftman
// verif import ensuite faire le update
//UPDATE `crma_record` SET `state` = '3' WHERE `state` = '1'
$query = $pdo->prepare($sql);
$query->bindParam(':siret', $row[0], PDO::PARAM_INT);
$query->bindParam(':raison_sociale', $row[1], PDO::PARAM_STR);
$query->bindParam(':forme_juridique', $row[2], PDO::PARAM_STR);
$query->bindParam(':nom_commerciale', $row[3], PDO::PARAM_STR);
$query->bindParam(':code_ape', $row[5], PDO::PARAM_INT);
$query->bindParam(':libelledeux', $row[8], PDO::PARAM_STR);
$query->bindParam(':enseigne', $row[4], PDO::PARAM_STR);
$query->bindParam('aujourdhui',$time, PDO::PARAM_INT);
$query->bindParam('libelleun', $row[7], PDO::PARAM_STR);
$query->bindParam('voie', $row[9], PDO::PARAM_STR);
$query->bindParam('complement', $row[10], PDO::PARAM_STR);
$query->bindParam('codepostale', $row[11], PDO::PARAM_INT);
$query->bindParam('commune', $row[12], PDO::PARAM_STR);
$query->bindParam('canto', $row[13], PDO::PARAM_STR);
$query->bindParam('telephone', $row[14], PDO::PARAM_INT);
$query->bindParam('email', $row[15], PDO::PARAM_STR);
$query->execute();
}
}
// redirect to the index page
header('location: index.php');
?> |
Partager