Advertisement
Guest User

Database to JSON

a guest
Aug 20th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.49 KB | None | 0 0
  1. <?php  
  2.     $username ="daengid_isfaaghyth";
  3.     $password ="sensor";
  4.     $hostname = "localhost";
  5.     $database_name = "daengid_daengbelajar";
  6.    
  7.     $con = mysqli_connect($hostname , $username, $password);
  8.     $selected = mysqli_select_db($con, $database_name);
  9.  
  10.     $result = mysqli_query($con, "SELECT * FROM wrshop_planet");
  11.     $json_response = array();
  12.    
  13.     while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
  14.         $json_response[] = $row;
  15.     }
  16.  
  17.     echo json_encode(array('planet' => $json_response));  
  18.  
  19. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement