Créer le tableau qui va accueillir les données
Créer le fichier excel qui sera converti en csv. Ce fichier doit avoir les entetes et des colonnes du tableau. La colonne id doit être aussi crée dans le csv.
uploader le fichier csv dans le sous repertoire /csv et modifier le filepath
$con = mysqli_connect("host", "roots", "password", "database_name") or die(mysql_error()); $filePath = "/home1/monsite/public_html/repertoire/csv/nom_fichier_csv.csv"; $tableName = "nom_de_la_table"; $fieldDelimiter = ","; $lineDelimiter = "\n"; // If your csv file has not a header row, remove the line "IGNORE 1 LINES". mysqli_query($con, ' LOAD DATA LOCAL INFILE "'.$filePath.'" INTO TABLE '.$tableName.' FIELDS TERMINATED by \'' . $fieldDelimiter . '\' LINES TERMINATED BY \'' . $lineDelimiter . '\' IGNORE 1 LINES ') or die(mysql_error()); $query = mysqli_query($con, "SELECT COUNT(*) AS total_rows FROM " . $tableName); $result = mysqli_fetch_array($query); $total_rows = $result['total_rows']; echo $total_rows . " rows have been added to the table " . $tableName;
source: https://github.com/jonseg/csv-to-mysql