Advertisement
Guest User

Untitled

a guest
Nov 21st, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. <?php
  2. // header('Access-Control-Allow-Origin: *');
  3. // header('Access-Control-Allow-Headers: *');
  4. // header('Access-Control-Allow-Methods: GET, POST, PUT');
  5. header('Content-Type: application/json');
  6.  
  7. $servername ="localhost";
  8. $username ="root";
  9. $password ="";
  10. $dbname= "aula";
  11.  
  12. //Criar conexao
  13.  
  14. $conn = new MySQLi($servername,$username,$password,$dbname);
  15.  
  16. //Ver conexao
  17.  
  18. if($conn ->connect_error){
  19. die("Connection failed: " . $conn->connect_error);
  20. }
  21.  
  22. $res = mysqli_query($conn, "SELECT * FROM veiculo");
  23.  
  24. $datarequest = array();
  25. if ((count($_REQUEST) > 0))
  26. $datarequest = $_REQUEST;
  27. $q = $datarequest['q'];
  28. unset($datarequest['q']);
  29. unset($_REQUEST['q']);
  30.  
  31. switch($q){
  32. case 'carro':{
  33. if ($res->num_rows > 0) {
  34. while($row = mysqli_fetch_assoc($res))
  35. $test[] = $row;
  36. echo json_encode($test);
  37. }
  38. break;
  39. }
  40. }
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement