Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header('Access-Control-Allow-Origin: *');
- header('Content-Type: application/json; charset=utf-8');
- $method = (isset($_GET["method"]) ? $_GET["method"] : "");
- # $host = "localhost";
- # $user = ""; //preenche estes campos
- # $pass = ""; //preenche estes campos
- # $db = ""; //preenche estes campos
- if(mysql_connect($host, $user, $pass)) {
- mysql_select_db($db);
- } else {
- die("Can't connect to DB");
- }
- switch($method) {
- case "method1":
- $data = mysql_query("query1 aqui");
- $rows = array();
- while($r = mysql_fetch_assoc($data)) {
- $rows[] = $r;
- }
- echo json_encode($rows);
- break;
- case "method2":
- $data = mysql_query("query1 aqui");
- $rows = array();
- while($r = mysql_fetch_assoc($data)) {
- $rows[] = $r;
- }
- echo json_encode($rows);
- break;
- default:
- echo "Not a valid method.";
- break;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement