1

I am going crazy with one problem in my web app.

I have a SCADA system that everyday dumps excel files to my server with data from one thermal plant.

I have a web app in PHP / Jquery that reads this data from a MySQL database and show this in charts and tables.

But I have to manually import the excel files to MySQL. What I want to do, is to build a PHP script, that will do as follow:

The user tries to make a chart, and if the data is not on MySQL it will ask if he wants to import the data from the excel files in the server. Than the excel files are copied into MySQL temporary tables and inserted into the correspond table. Then the data can be displayed to the user and will keep stored in the MySQL database.

All its working, but I need make an automatic way to import this data from the excel files to MySQL tables.

Thanks in advance for your help

9
  • So which of the many PHP libraries capable of reading Excel files have you looked at, and what problems have you encountered with them? Commented Dec 18, 2013 at 23:33
  • Thank you Mark for taking the time to read this! I have looked into some.. But most of them is necessary to convert the excel file into csv. Now I was looking into phpexcel.codeplex.com. Note: The excel files have personalised extensions. They can be open in MS access. Commented Dec 18, 2013 at 23:35
  • 1
    In addition to my own PHPExcel, There are a number of PHP libraries for reading real Excel BIFF (.xls) or OfficeOpenXML (.xlsx) files (not simply csv files) listed in my answer to this question Commented Dec 18, 2013 at 23:51
  • Thank you Mark! I'll try PHPExcel and SimpleExcel! Commented Dec 19, 2013 at 0:07
  • Mark, just one question. My files are dBase IV not excel. Is it possible with this libraries? Commented Dec 19, 2013 at 10:02

1 Answer 1

1

hey there actually i had the same problem before i did the following to solve it: create a function in php to execute query to import the file from your destination public function InsertNewData($filename){ $dbtable = substr($filename, 0,-4);

    $sql = " LOAD DATA LOCAL INFILE 'http://your-ip-and-root/uploads/$filename'"
         . " INTO TABLE $dbtable FIELDS TERMINATED BY ';' LINES TERMINATED BY '\\n'";
    $error = " <font color = 'red'>error Load Data the file Please contact the DB Admin </font>";
    $connection = ResourceManager::getConnection();
    $resultado = 0;
    $connection->beginTransaction();
    try {
        $prepare = $connection->prepare($sql);                     
        $prepare->execute();    
        $connection->commit();
    } catch (Exception $e) {
       echo $error;          
        $connection->rollBack();

    }
    $connection = null;

} and then you can call this function from your page when upload excel file is completed

hope it helped.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.