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";
$row = 1;
if (($handle = fopen($file, "r")) !== FALSE)
{
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$str_values = implode(',', $data);
//echo $str_values . "\n";
$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(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", $str_values[0], $str_values[1], $str_values[2], $str_values[3], $str_values[4], $str_values[5], $str_values[6], $str_values[7], $str_values[8], $str_values[9], $str_values[10], $str_values[11], 6);
}
fclose($handle);
}
}
else
{
echo "File $file not found or is unreadable!\n";
}
?>