[eluser]Wondering Coder[/eluser]
Hi to all,
I'm been trying to upload a .csv file and save it to my table. But it gives me an error.
this is my model
Code:
function save_csv($data)
{
$query = $this->db->query("LOAD DATA LOCAL INFILE $data
INTO TABLE pps_test
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(test_name, test_age)");
return $query;
}
My controller
Code:
if($save)
{
$config = array(
'upload_path' => './media/csv/',
'allowed_types' => 'csv',
'max_size' => '100',
);
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$data['error'] = $this->upload->display_errors('<p class="error">','</p>');
}
else
{
#$this->upload->do_upload();
$image_data = $this->upload->data();
//print_r($image_data);
$this->admin_db->save_csv($image_data['full_path']);
}
}
and this is the error that gives me:
Code:
A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'C:/xampp/htdocs/dcs-pps/media/csv/Book14.csv INTO TABLE pps_tes' at line 1
LOAD DATA LOCAL INFILE C:/xampp/htdocs/dcs-pps/media/csv/Book14.csv INTO TABLE pps_test FIELDS TERMINATED BY ',' LINES TERMINATED BY ' ' (test_name, test_age)
Filename: C:\xampp\htdocs\dcs-pps\system\database\DB_driver.php
Line Number: 330
Hope anyone can help me in here.