Jump to content

Using PHP to Load Data - Help Please


spires

Recommended Posts

Hi guys

 

I'm trying to build a php script that will allow me to upload a csv file

into a mysql database.

 

I've upload the .csv file to the server where the script will be.

 

Here the script

$query  = "load data infile 'upload.csv' INTO TABLE test1";
$result = mysql_query($query) or die (mysql_error());

 

However, this does not work.

 

Any ideas?

 

Thanks for your help.

Link to comment
Share on other sites

Yes, the .csv file is on the server in the same folder as the .php file

 

The .csv file is formatted like this:

 

CustomerID , CustomerName, OrderID, OrderDate

1, 2, 3, 4

5, 6, 7, 8

 

 

The Date Base table is as follows:

CustomerID , CustomerName, OrderID, OrderDate

 

 

Should the .csv file be on the server?

 

 

Thanks

Link to comment
Share on other sites

Yes, this is the error:

Access denied for user 'mobiles'@'localhost' (using password: YES)

 

 

Lol.

 

You have to use mysql_connect() to open a connection with the MySQL server associated with your site. Then, you have to use mysql_select_db() to select a database with which you'd like to interact.

 

Both of these must be used before you attempt to execute any MySQL queries.

 

Edit: I see that you actually have already implemented these two functions. So, the problem, clearly, is that your username and password credentials are collectively invalid.

Link to comment
Share on other sites

Yes, this is the error:

Access denied for user 'mobiles'@'localhost' (using password: YES)

 

 

Lol.

 

You have to use mysql_connect() to open a connection with the MySQL server associated with your site. Then, you have to use mysql_select_db() to select a database with which you'd like to interact.

 

Both of these must be used before you attempt to execute any MySQL queries.

 

Edit: I see that you actually have already implemented these two functions. So, the problem, clearly, is that your username and password credentials are collectively invalid.

 

maybe he still dosent have any access if he hasent thoght about connect if this is a shared server he defo hasent thoght about adding users to the db.

Link to comment
Share on other sites

I am connecting to the database.

include("../dbconnect.php");

 

If I select from any of the other tables within the database it works fine.

However, when ever I try to run the 'LOAD DATA' script it come up with

that error

 

Any ideas?

Link to comment
Share on other sites

This works:

$query  = "SELECT * FROM test1";

$result = mysql_query($query) or die (mysql_error());

 

But this throws up the error:

$query  = "load data infile 'upload.csv' INTO TABLE test1";

$result = mysql_query($query) or die (mysql_error());

 

Link to comment
Share on other sites

This works:

$query  = "SELECT * FROM test1";

$result = mysql_query($query) or die (mysql_error());

 

But this throws up the error:

$query  = "load data infile 'upload.csv' INTO TABLE test1";

$result = mysql_query($query) or die (mysql_error());

 

 

That probably means that the user "mobile" doesn't have the privilege to utilize the LOAD DATA INFILE syntax. Check the privileges on said user.

Link to comment
Share on other sites

well it obviously has to be on the server for you to interact with the file using your mysql server and you have to specify where it is on your server

 

That probably means that the user "mobile" doesn't have enough the privilege to utilize the LOAD DATA INFILE syntax. Check the privileges on said user.

 

true

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.