Search code examples
phpexceltextcsvoscommerce

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


I would like to convert a text file to excel and then modify certain data inside the excel file and then import this new excel file to a database.

The contents of the excel file, for example, will be products and their prices and the modification will be on the prices. So the update of the products in the database and on the website will be automatic. I am planning to use OSCommerce

My question is this: Is there any tool for OSCommerce that I will configure it to do this job for me as I need to do this automatically every 8 hours for example? I need to write a script from scratch using PHP?


Solution

  • If you save the excel file in a simple csv (comma separated value) format than you could easily split it by the commas and organize your data using PHP.

    You would use the following code to read the data from the file:

    $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
    

    This is just a basic script, and would need to be manipulated by yourself to work for your needs. God luck :)