load.php 870 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * This is an example code that shows how you can load Handsontable data from server using PHP with PDO (SQLite).
  4. * This code is not intended to be maximally efficient nor safe. It is for demonstrational purposes only.
  5. * Changes and more examples in different languages are welcome.
  6. *
  7. * Copyright 2012, Marcin Warpechowski
  8. * Licensed under the MIT license.
  9. * http://github.com/handsontable/handsontable/
  10. */
  11. require_once('functions.php');
  12. try {
  13. //open the database
  14. $db = getConnection();
  15. if(!carsTableExists($db)){
  16. resetCarsTable($db);
  17. }
  18. //select all data from the table
  19. $result = loadCars($db);
  20. $out = array(
  21. 'cars' => $result->fetchAll(PDO::FETCH_ASSOC)
  22. );
  23. echo json_encode($out);
  24. // close the database connection
  25. closeConnection($db);
  26. }
  27. catch (PDOException $e) {
  28. print 'Exception : ' . $e->getMessage();
  29. }
  30. ?>