Advertisement
Guest User

php

a guest
Sep 22nd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.73 KB | None | 0 0
  1. <?php
  2.  
  3. $response = array();
  4. include 'db_connect.php';
  5.  
  6. $db = new DB_CONNECT();
  7. include 'db_config.php';
  8.  
  9. $con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE) or die(mysqli_error($con));
  10. $result = mysqli_query($con, "SELECT id, username FROM usuario") or die(mysqli_error($con));
  11.  
  12. if(mysqli_num_rows($result)>0){
  13. $response["usuario"] = array();
  14.  
  15. while($row = mysqli_fetch_array ($result)){
  16. $product = array();
  17. $product['id'] = $row['id'];
  18. $product['username'] = $row['username'];
  19.  
  20. array_push($response["usuario"], $product);
  21. }
  22.  
  23. $response["success"]=1;
  24. echo json_encode($response);
  25.  
  26. }
  27. else{
  28. $response["success"]=0;
  29. $response["message"]="Nenhum usuario cadastrado";
  30.  
  31. echo json_encode($response);
  32. }
  33. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement