我编写的脚本有问题,该脚本用于从 csv 文件的内容自动更新库存水平。在我的本地 zend 服务器上,它运行良好。注意,phpMyAdmin 有 root 用户,没有密码。
但是,当上传到客户端服务器时,我收到一条错误消息:
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
代码部分如下:
//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";
我知道与数据库的连接没问题,因为我得到回声说历史库存已被清除,所以我不明白为什么当它到达应该读取 csv 内容的部分时出现访问被拒绝错误进入临时表。
如前所述,这在我的本地 zend 服务器上完美运行。
在我把头发扯掉之前,任何帮助都非常感谢