Log in

View Full Version : using LOAD DATA INFILE



fastsol1
08-27-2010, 02:55 AM
So I have a project coming up that I will most likely need to use this, so I was testing to make sure I understand how to do it beforehand. Here is the code I am using


if (isset($_POST['load']))
{
require('connect2.php');
$temp = $_FILES['myfile']['tmp_name'];
$sqlstatement="LOAD DATA INFILE '$temp' INTO TABLE inventory FIELDS TERMINATED BY ',' ";
mysql_query($sqlstatement) or die(mysql_error());
echo "It worked";
}



<form method="post" action="load.php" enctype="multipart/form-data">
<input name="myfile" type="file" />
<input name="load" type="submit" value="submit" /></form>

The reason I want to use this I think is cause the file that the client will be using is a exported csv file from Quickbooks and I want it to be easy for them to upload and have it update their inventory on the site and this will be a long inventory list.

Now the issue I am having is that when I try the upload it seems to do that fine but gives me this

Access denied for user 'C304016_rsmnprod'@'%' (using password: YES)

I am using the same exact connect.php that the entire rest of the site uses to display all the data currently in the DB so I know that that is correct. I even called my hosting company to verify if they know if the server allows or not the LOAD DATA INFILE, they are checking at the moment. Now I have used INSERT on many pages without fail and I understand this is variation of that so why does it give me the error.

The table exists in the DB and has columns labeled accordingly, also it doesn't matter what type of file I try it gives the same message.

fastsol1
08-27-2010, 03:12 AM
So why is it right after I post something I find the answer. Found a note the if the script is on a hosting server you need to include LOCAL in the query. So like this
$sqlstatement="LOAD DATA LOCAL INFILE '$temp' INTO TABLE inventory FIELDS TERMINATED BY ',' ";