read.php 481 B

123456789101112131415161718192021222324
  1. <?php
  2. include '../connection.php';
  3. try {
  4. $statement = $db->prepare('select * from task');
  5. if(!$statement->execute()) {
  6. throw new Exception(implode(', ', $statement->errorInfo()));
  7. }
  8. $jsonResult = array(
  9. 'success' => true,
  10. 'tasks' => $statement->fetchAll(PDO::FETCH_ASSOC)
  11. );
  12. } catch(Exception $e) {
  13. $jsonResult = array(
  14. 'success' => false,
  15. 'message' => $e->getMessage()
  16. );
  17. }
  18. echo json_encode($jsonResult);
  19. ?>