Guest User

Untitled

a guest
Oct 5th, 2014
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.12 KB | None | 0 0
  1. <?php
  2.  date_default_timezone_set('UTC');
  3. try {
  4.  
  5.     $objDb = new PDO('sqlite:../dbase/shopper');
  6.  
  7.     $objDb -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  8.    
  9.     $sql = "SELECT item.* ,
  10.             t.name AS type_name
  11.             FROM items item
  12.             INNER JOIN types t
  13.             ON t.id = item.type
  14.             ORDER BY item.date ASC";
  15.  
  16.     $result = $objDb->query($sql);
  17.    
  18.     if(!$result) {
  19.  
  20.         throw new  PDOException("The result returned no object");
  21.  
  22.     }
  23.     $result->setFetchMode(PDO::FETCH_ASSOC);
  24.  
  25.     $items = $result->fetchAll();
  26.  
  27.     $sql = "SELECT *
  28.             FROM types
  29.             ORDER BY id";
  30.     $result = $objDb->query($sql);
  31.     echo var_dump($result);
  32.     if(!$result) {
  33.  
  34.         throw new  PDOException("The result returned no object");
  35.  
  36.     }
  37.     $result->setFetchMode(PDO::FETCH_ASSOC);
  38.     $types = $result->fetchAll();
  39.  
  40.     echo json_encode(array(
  41.         'error' => false,
  42.         'items' => $items,
  43.         'types' => $types
  44.     ), JSON_HEX_TAG | JSON_HEX_APOS |JSON_HEX_QUOT |JSON_HEX_AMP );
  45.  
  46. } catch (PDOException $e) {
  47.    
  48.     echo json_encode(array(
  49.         'error' => true,
  50.         'message' => $e->getMessage()
  51.     ),JSON_HEX_TAG | JSON_HEX_APOS |JSON_HEX_QUOT |JSON_HEX_AMP );
  52. }
Advertisement
Add Comment
Please, Sign In to add comment