Advertisement
Guest User

Untitled

a guest
Feb 21st, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. $.ajax({
  2. type: "GET",
  3. url: "connect/database.php",
  4. dataType: "json",
  5. success: function(response){
  6. alert(response);
  7. }
  8. });
  9.  
  10. <?php
  11.  
  12.  
  13. $servername = "localhost";
  14. $username = "the_username";
  15. $password = "the_password";
  16. $dbname = "the_db";
  17.  
  18. // create connection
  19. $conn = new mysqli($servername, $username, $password, $dbname);
  20. // Check connection
  21. if ($conn->connect_error) {
  22. die("Connection failed: " . $conn->connect_error);
  23. }
  24.  
  25. $array_result = array();
  26.  
  27. $sql = mysqli_query("select * from table where user = 'bobo'");
  28. $result = $conn->query($sql);
  29.  
  30. if ($result->num_rows > 0) {
  31. // output data of each row
  32. while($row = $result->fetch_assoc()) {
  33. $array_result[] = $row;
  34. }
  35. } else {
  36. echo "0 results";
  37. }
  38.  
  39. $conn->close();
  40.  
  41. print json_encode($array_result)
  42.  
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement