Advertisement
joris

Sample PHP

Sep 29th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.75 KB | None | 0 0
  1. <?php
  2. include 'config.php';
  3.  
  4. $sql = "select * from epg e where e.channel_code='APL' order by e.id ASC";
  5.  
  6. try {
  7.     $dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass); 
  8.     $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  9.     $stmt = $dbh->query($sql);  
  10.     $SistemPakar= $stmt->fetchAll(PDO::FETCH_OBJ);
  11.     $dbh = null;
  12.     $json = json_encode($SistemPakar);
  13.    
  14.    
  15.     // Using JSONP
  16.     if ($_GET['callback']) {
  17.          echo $_GET['callback'] . "($json);"; // somefunction({data here});
  18.    
  19.     // Normal JSON
  20.     } else {
  21.         //echo $json;
  22.         echo '{"items":'. json_encode($SistemPakar) .'}';
  23.     }
  24.     //echo '{"items":'. json_encode($SistemPakar) .'}';
  25. } catch(PDOException $e) {
  26.     echo '{"error":{"text":'. $e->getMessage() .'}}';
  27. }
  28.  
  29.  
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement