0

I'm having problems with a script i wrote to automatically update stock levels from the contents of a csv file. On my local zend server it worked perfectly. Note, phpMyAdmin has user root, no password.

But, when uploaded to the clients server i get an error message:

PHP Fatal error:  1045:Access denied for user 'xxxxxx_xxxxxx'@'localhost' (using password: YES) ::     LOAD DATA INFILE '/home/xxxxxxxx/public_html/tradeboxstock/stock.csv'
 INTO TABLE stock_temp
 FIELDS TERMINATED BY ','
 ENCLOSED BY '"'
 LINES TERMINATED BY '
'  (products_model, products_quantity); in /home/xxxxxxxx/public_html/includes/classes/db/mysql/query_factory.php on line 121

The section of code is below:

//Set directory of csv file
$file_path = DIR_FS_CATALOG . 'tradeboxstock/stock.csv';

// Empty old data from the temp table
$db->Execute("DELETE FROM ".TABLE_STOCK_TEMP."");
$table = ("".TABLE_STOCK_TEMP."");
echo "Historical stock data cleared";
?>
</br>
<?php
echo "Processing - Please wait...";

//extract data from the csv to the temp table
$query = <<<eof
LOAD DATA INFILE '$file_path'
INTO TABLE $table
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
(products_model, products_quantity);
eof;
$db->Execute($query);
echo "Import to temp database table complete";

I know that the connection to the database is ok because i get the echo to say that historical stock has been cleared, so i don't understand why i get an access denied error when it gets to the section where it should read the csv contents into the temp table.

As stated, this works perfectly on my local zend server.

Any help much appreciated before i tear my hair out

Steve Price
  • 600
  • 10
  • 28

1 Answers1

0

Check the privileges granted to the PHP user being used to connect to MySQL.

mysql> SHOW GRANTS FOR 'user'@'localhost'

For the import to work the user firing the LOAD DATA must have the FILE privilege.

mysql> GRANT FILE ON *.* TO 'user'@'localhost'
Ravi K Thapliyal
  • 51,095
  • 9
  • 76
  • 89