Guest User

Untitled

a guest
Jan 9th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. <?php
  2.  
  3. header('Content-Type: text/plain');
  4.  
  5. $Filepath = "./test.xlsx";
  6.  
  7. require('SpreadsheetReader.php');
  8.  
  9. $user = 'root';
  10. $pass = '';
  11.  
  12. $dbh = new PDO('mysql:host=localhost;dbname=results', $user, $pass);
  13. $sql = "DELETE FROM t_results WHERE id";
  14.  
  15. $dbh->exec($sql);
  16.  
  17. try
  18. {
  19. $Spreadsheet = new SpreadsheetReader($Filepath);
  20.  
  21. $Sheets = $Spreadsheet -> Sheets();
  22.  
  23.  
  24. foreach ($Sheets as $Index => $Name)
  25. {
  26.  
  27. $Spreadsheet -> ChangeSheet($Index);
  28.  
  29. foreach ($Spreadsheet as $Key => $Row)
  30. {
  31. if ($Row)
  32. {
  33. if($dbh){
  34. $sql = "INSERT INTO t_results (id, name, class, score)
  35. VALUES ('$Row[0]', '$Row[1]', '$Row[2]', '$Row[3]')";
  36. $dbh->exec($sql);
  37. echo $Row[3];
  38. }
  39. }
  40. else
  41. {
  42. var_dump($Row);
  43. }
  44. }
  45. }
  46. }
  47. catch (Exception $E)
  48. {
  49. echo $E -> getMessage();
  50. }
  51. ?>
Add Comment
Please, Sign In to add comment