spires Posted May 19, 2009 Share Posted May 19, 2009 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. Quote Link to comment Share on other sites More sharing options...
Masna Posted May 19, 2009 Share Posted May 19, 2009 Is this file formatted correctly? Also, does it actually exist on the server? http://dev.mysql.com/doc/refman/5.1/en/load-data.html Quote Link to comment Share on other sites More sharing options...
spires Posted May 19, 2009 Author Share Posted May 19, 2009 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 Quote Link to comment Share on other sites More sharing options...
Masna Posted May 19, 2009 Share Posted May 19, 2009 Are any errors printed when the query is attempted to be executed? Quote Link to comment Share on other sites More sharing options...
spires Posted May 19, 2009 Author Share Posted May 19, 2009 Yes, this is the error: Access denied for user 'mobiles'@'localhost' (using password: YES) Quote Link to comment Share on other sites More sharing options...
Masna Posted May 19, 2009 Share Posted May 19, 2009 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. Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted May 19, 2009 Share Posted May 19, 2009 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. Quote Link to comment Share on other sites More sharing options...
spires Posted May 19, 2009 Author Share Posted May 19, 2009 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? Quote Link to comment Share on other sites More sharing options...
spires Posted May 19, 2009 Author Share Posted May 19, 2009 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()); Quote Link to comment Share on other sites More sharing options...
Masna Posted May 19, 2009 Share Posted May 19, 2009 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. Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted May 19, 2009 Share Posted May 19, 2009 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 Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted May 19, 2009 Share Posted May 19, 2009 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.