Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- date_default_timezone_set('UTC');
- try {
- $objDb = new PDO('sqlite:../dbase/shopper');
- $objDb -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $sql = "SELECT item.* ,
- t.name AS type_name
- FROM items item
- INNER JOIN types t
- ON t.id = item.type
- ORDER BY item.date ASC";
- $result = $objDb->query($sql);
- if(!$result) {
- throw new PDOException("The result returned no object");
- }
- $result->setFetchMode(PDO::FETCH_ASSOC);
- $items = $result->fetchAll();
- $sql = "SELECT *
- FROM types
- ORDER BY id";
- $result = $objDb->query($sql);
- echo var_dump($result);
- if(!$result) {
- throw new PDOException("The result returned no object");
- }
- $result->setFetchMode(PDO::FETCH_ASSOC);
- $types = $result->fetchAll();
- echo json_encode(array(
- 'error' => false,
- 'items' => $items,
- 'types' => $types
- ), JSON_HEX_TAG | JSON_HEX_APOS |JSON_HEX_QUOT |JSON_HEX_AMP );
- } catch (PDOException $e) {
- echo json_encode(array(
- 'error' => true,
- 'message' => $e->getMessage()
- ),JSON_HEX_TAG | JSON_HEX_APOS |JSON_HEX_QUOT |JSON_HEX_AMP );
- }
Advertisement
Add Comment
Please, Sign In to add comment