I've been trying to implement import and I've modified the file US.txt by replacing "\t" with " , " on each line just for a better practicality with my code. However, I receive the following error:
Below is my code:
<?php
require("../includes/config.php");
$argument = $argv[1];
$file = (__DIR__ . "/$argument");
// I'm using only is_readable because this function also checks if the file exists on it's own
if(is_readable($file))
{
echo "File $file found!\n";
if (($handle = fopen($file, "r")) !== FALSE)
{
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$insert = query("INSERT INTO places (country_code, postal_code, place_name, admin_name1, admin_code1, admin_name2, admin_code2, admin_name3, admin_code3, latitude, longitude, accuracy) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", $data[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6], $data[7], $data[8], $data[9], $data[10], 6);
}
fclose($handle);
}
}
else
{
echo "File $file not found or is unreadable!\n";
}
?>
This is how I've modified my US.txt file: