每天自动将excel/csv文件导入我的数据库


Oscommerce and automatic import of excel/csv file to my database on a daily basis

我想将文本文件转换为excel,然后修改excel文件中的某些数据,然后将这个新的excel文件导入数据库。

例如,excel文件的内容将是产品及其价格,修改将基于价格。因此,数据库和网站上的产品更新将是自动的。我计划使用OSCommerce

我的问题是:有没有OSCommerce的任何工具,我会配置它来为我做这项工作,例如,我需要每8小时自动完成一次?我需要用PHP从头开始写一个脚本吗?

如果您将excel文件保存为简单的csv(逗号分隔值)格式,则可以很容易地用逗号将其拆分,并使用PHP组织数据。

您将使用以下代码从文件中读取数据:

$file_name = "test.csv"; // This needs to be relative to the current location that this script is being executed in 
$fp = fopen($file_name, "r"); // "r" means read, change to "rw" or "w" for read/write and write as needed
$data = fread($fp, filesize($file_name)); // Read the contents of the file into a string
fclose($fp); // Close the file for efficiency
$data = explode(',', $data); // Override data with the array format

这只是一个基本的脚本,需要您自己操作才能满足您的需求。好运:)