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
https://forums.phpfreaks.com/topic/158727-using-php-to-load-data-help-please/
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

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.

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.

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.