Though you can import the CSV directly in DB, but importing it with an importer gives you more control over the data manipulation while importing.
Below is the Script you will be needing for that.
<?php
/**
* importer for CSV in MySQL DB.
* pleas keep the CSV file in the same directory and run :
*
* > php ./import.php
*/
$host = "localhost"; // Host name.
$db_user = "root"; //mysql user
$db_password = ""; //mysql pass
$db = ''; // Database name.
$con = mysqli_connect($host, $db_user, $db_password, $db);
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$file = fopen('filename.extension', "r");
while (($data = fgetcsv($file, 100000, ",")) !== FALSE) {
$sql = "INSERT into hs_codes(col1, col2, col3) values('$data[0]', '$data[1]', '$data[2]')";
mysqli_query($con, $sql);
}
fclose($file);
echo "CSV File has been successfully Imported.";