Welcome Guest, Not a member yet? Register   Sign In
Database Error Number: 0
#1

[eluser]Dennis Geus[/eluser]
Hi all,

I'm uploading a .csv file and then insert the data into a temp table in the database.

I'm using the following piece of code:

Code:
$path = './uploads/';
$file = $upload_data['file_name'];
$fieldterm = ";";
$lineterm = "\\r\\n";

$this->db->query("LOAD DATA LOCAL INFILE '".$path.$file."' INTO TABLE temp FIELDS TERMINATED BY '".$fieldterm."' LINES TERMINATED BY '".$lineterm."' IGNORE 1 LINES");

It ends up with the following error:

Quote:A Database Error Occurred
Error Number: 0


LOAD DATA LOCAL INFILE './uploads/export_uit_sap7.csv' INTO TABLE temp FIELDS TERMINATED BY ';' LINES TERMINATED BY '\r\n' IGNORE 1 LINES

Filename: G:\Inetpub\development\qc\system\database\DB_driver.php

Line Number: 330

But when I check the temp table it is filled with the data of the csv file.

in my logfile i find this line:
Quote:Severity: Warning --&gt; mysql_query() [<a href='function.mysql-query'>function.mysql-query</a>]: Unable to save result set G:\Inetpub\development\qc\system\database\drivers\mysql\mysql_driver.php 163

After a few hours of searching I think I can't find it.

If someone can point me to the right direction or can come up with a workaround i would appreciate it. Smile
#2

[eluser]Dennis Geus[/eluser]
I think I solved it by using the simple_query
$this->db->simple_query("LOAD DATA ....

now testing it and expanding the code to do more with the data.
#3

[eluser]rogerwaldrup[/eluser]
Let us know how it works out. It's always good to learn how a problem was solved.
#4

[eluser]Dennis Geus[/eluser]
ok,
well it's working.

Code:
$path = './uploads/';
$file = $upload_data['file_name'];
if ($upload_data['file_ext'] == ".csv") {
$fieldterm = ";";
$lineterm = "\\r\\n";
}
if ($upload_data['file_ext'] == ".txt") {
$fieldterm = "\\t";
$lineterm = "\\r\\n";
}

$this->db->simple_query("LOAD DATA LOCAL INFILE '".$path.$file."' INTO TABLE temp FIELDS TERMINATED BY '".$fieldterm."' LINES TERMINATED BY '".$lineterm."' IGNORE 1 LINES");

The only problem is that it always returns als FALSE (but it inserts the data), so I can't do any checks with it.

I think I'll have to do a query on the temp table to see if it has data before I continue with the rest.




Theme © iAndrew 2016 - Forum software by © MyBB