Advertisement
Guest User

Untitled

a guest
Dec 20th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. <?php
  2. header("Content-type:application/json");
  3.  
  4. $servername = "sasdasdasdadsdom";
  5. $username = "adsdas78";
  6. $password = "veasdasd1305";
  7. $database = "fasdfasdfasdf";
  8.  
  9. //creating a new connection object using mysqli
  10. $conn = new mysqli($servername, $username, $password, $database);
  11.  
  12. //if there is some error connecting to the database
  13. //with die we will stop the further execution by displaying a message causing the error
  14. if ($conn->connect_error) {
  15. die("Connection failed: " . $conn->connect_error);
  16. }
  17.  
  18. //if everything is fine
  19.  
  20. //creating an array for storing the data
  21. $heroes = array();
  22.  
  23.  
  24.  
  25. //this is our sql query
  26. $sql = "SELECT * FROM `mov_en` LIMIT 0 , 30;";
  27.  
  28.  
  29.  
  30. //creating an statment with the query
  31. $stmt = $conn->prepare($sql);
  32.  
  33.  
  34. //executing that statment
  35. $stmt->execute();
  36.  
  37.  
  38. //binding results for that statment
  39. $stmt->bind_result($id, $name,$img,$quality,$down);
  40.  
  41.  
  42. //looping through all the records
  43. while($stmt->fetch()){
  44.  
  45. //pushing fetched data in an array
  46. $temp = [
  47. 'id'=>$id,
  48. 'name'=>$name,
  49. 'img'=>$img,
  50. 'quality'=>$quality,
  51. 'down'=>$down
  52. ];
  53. array_push($heroes, $temp);
  54.  
  55.  
  56. }
  57. echo json_encode($heroes);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement