Import .xls file to database using F3

56 views
Skip to first unread message

Jago Kapok

unread,
Apr 25, 2017, 6:03:27 AM4/25/17
to f3-fra...@googlegroups.com
In pure php (require excel_reader library), I can import .xls file to database with this code :

if(isset($_POST['submit'])){
    $target
= basename($_FILES['file_excel']['name']) ;
    move_uploaded_file
($_FILES['file_excel']['tmp_name'], $target);
   
    $data
= new Spreadsheet_Excel_Reader($_FILES['file_excel']['name'],false);
   
   
// count row xls file
    $row
= $data->rowcount($sheet_index=0);
   
   
// import data excel from line 2
   
for ($i = 2; $i <= $row; $i++)
   
{
     
// read data
      $name     
= $data->val($i, 1);
      $address  
= $data->val($i, 2);
      $date     
= $data->val($i, 3);

     
// insert to mysql database
      $query
= "INSERT into table(name,address,date)values('$name','$address','$date')";
      $result
= mysql_query($query);
   
}
   
   
if(!$result){
       
// if failed
         
die(mysql_error());
     
} else {
       
// if success
          echo
"Success";
   
}
   
   
// delete xls file
    unlink
($_FILES['file_excel']['name']);
}

My question is, how to do it in F3 ?

ikkez

unread,
Apr 25, 2017, 6:35:18 AM4/25/17
to Fat-Free Framework
exactly the same.. you can just switch to the DB class, instead:

mysql_query($query);

you can use $db->exec($query);

that's pretty much it.

Jago Kapok

unread,
Apr 25, 2017, 10:10:10 PM4/25/17
to f3-fra...@googlegroups.com
It's work. Thanks bro
Reply all
Reply to author
Forward
0 new messages