Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. <?php
  2. header('Access-Control-Allow-Origin: *');  
  3. header('Content-Type: application/json; charset=utf-8');
  4.  
  5. $method = (isset($_GET["method"]) ? $_GET["method"] : "");
  6.  
  7. # $host = "localhost";
  8. # $user = "";   //preenche estes campos
  9. # $pass = "";   //preenche estes campos
  10. # $db = "";     //preenche estes campos
  11. if(mysql_connect($host, $user, $pass)) {
  12.     mysql_select_db($db);
  13. } else {
  14.     die("Can't connect to DB");
  15. }
  16.  
  17. switch($method) {
  18.     case "method1":
  19.         $data = mysql_query("query1 aqui");
  20.         $rows = array();
  21.         while($r = mysql_fetch_assoc($data)) {
  22.             $rows[] = $r;
  23.         }
  24.         echo json_encode($rows);
  25.     break;
  26.     case "method2":
  27.         $data = mysql_query("query1 aqui");
  28.         $rows = array();
  29.         while($r = mysql_fetch_assoc($data)) {
  30.             $rows[] = $r;
  31.         }
  32.         echo json_encode($rows);
  33.     break;
  34.     default:
  35.         echo "Not a valid method.";
  36.     break;
  37. }
  38. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement