【问题标题】:Oscommerce and automatic import of excel/csv file to my database on a daily basisOscommerce 每天自动将 excel/csv 文件导入我的数据库
【发布时间】:2012-07-14 11:19:41
【问题描述】:

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

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

我的问题是:是否有任何 OSCommerce 工具可以配置为我完成这项工作,例如我需要每 8 小时自动执行一次?我需要使用 PHP 从头开始​​编写脚本吗?

【问题讨论】:

  • 据我所知 OSCommerce,您需要自己编写一个脚本。但这应该相对容易,因为您已经知道自己需要什么,并且在 PHP 中打开 CSV 文件非常简单,而且查询数据库也是如此。

标签: php excel text csv oscommerce


【解决方案1】:

如果您以简单的 csv(逗号分隔值)格式保存 excel 文件,则可以轻松地用逗号将其拆分并使用 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

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

【讨论】:

    猜你喜欢
    • 2021-04-12
    • 2010-10-04
    • 1970-01-01
    • 1970-01-01
    • 2016-12-30
    • 2014-11-05
    • 1970-01-01
    • 1970-01-01
    • 2017-11-15
    相关资源
    最近更新 更多