Welcome Guest, Not a member yet? Register   Sign In
load data infile
#1

[eluser]paynterc[/eluser]
I'm having difficulty with my "load data infile ..." command. I need to allow the user to load a tab-separated text file via a web form and then import that file into a table.

This works fine outside of Codeigniter. In my CI application, though, I get the following error:


Error Number: 1148

The used command is not allowed with this MySQL version

load data local infile '/Library/WebServer/Documents/custchoice_dev/uploads/mymatrix13.txt' into table temp_matrix


Because my database and my web directory are on different servers, I followed the advice in this post :
http://ellislab.com/forums/viewthread/61963/

What's discussed in that post matches the general method I use in my normal PHP applications. I'm still getting the same error in CI though.

Uploading and importing data works fine with normal PHP applications running on the same servers.

Has anyone else run into this problem?




Here is some code:

function new_event_productmatrix(){
// This function controls the product matrix upload form
$data['tabnum']=2;
$data['step']=5;
$e_region_id=$this->uri->segment(3);
$data['e_region_id']=$e_region_id;
if(isset($_POST['uploadbutton'])){
//$config['upload_path'] = '/tmp/';
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'txt|xls|tab';
$config['max_size'] = '100';
$config['max_width'] = '245';
$config['max_height'] = '245';
$config['remove_spaces'] = true;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$data['error'] = $this->upload->display_errors();
}
else
{
$udata = $this->upload->data();
// make file writeable
exec("chmod 777 " . $udata['full_path']);

// shell script removes MAC line breaks and replaces them with Unix line breaks
$tempfile = $udata['file_path'] . "temp" . time();
exec(" tr '\r' '\n' < " . $udata['full_path'] . " > $tempfile" );

// shell script replaces multiple line breaks with a single one (useful for DOS format files)
exec(" tr -s '\n' < $tempfile > " . $udata['full_path'] );

$this->events_model->loadProductMatrix($udata['full_path']);
echo"<pre>"; print_r($udata); echo"</pre>";
}
}

$this->load->view('admin_tabs',$data);
$this->load->view('new_event/event_productmatrix',$data);
$this->load->view('footer');

}



And from my model:

function loadProductMatrix($file){
$this->db->query("
drop table if exists temp_matrix
");

$this->db->query("
CREATE TABLE temp_matrix (
q VARCHAR( 5 ) NOT NULL ,
n VARCHAR( 5 ) NOT NULL
)
");

$this->db->query("load data local infile '" . $file . "' into table temp_matrix");


}




Theme © iAndrew 2016 - Forum software by © MyBB