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. Link to comment https://forums.phpfreaks.com/topic/158727-using-php-to-load-data-help-please/ 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 Link to comment https://forums.phpfreaks.com/topic/158727-using-php-to-load-data-help-please/#findComment-837101 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 Link to comment https://forums.phpfreaks.com/topic/158727-using-php-to-load-data-help-please/#findComment-837105 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? Link to comment https://forums.phpfreaks.com/topic/158727-using-php-to-load-data-help-please/#findComment-837107 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) Link to comment https://forums.phpfreaks.com/topic/158727-using-php-to-load-data-help-please/#findComment-837110 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. Link to comment https://forums.phpfreaks.com/topic/158727-using-php-to-load-data-help-please/#findComment-837112 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. Link to comment https://forums.phpfreaks.com/topic/158727-using-php-to-load-data-help-please/#findComment-837115 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? Link to comment https://forums.phpfreaks.com/topic/158727-using-php-to-load-data-help-please/#findComment-837117 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()); Link to comment https://forums.phpfreaks.com/topic/158727-using-php-to-load-data-help-please/#findComment-837119 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. Link to comment https://forums.phpfreaks.com/topic/158727-using-php-to-load-data-help-please/#findComment-837124 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 Link to comment https://forums.phpfreaks.com/topic/158727-using-php-to-load-data-help-please/#findComment-837125 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 Link to comment https://forums.phpfreaks.com/topic/158727-using-php-to-load-data-help-please/#findComment-837126 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.