Advertisement
Guest User

Untitled

a guest
Sep 14th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. <?php
  2. $servername = "yourServerName.com";
  3. $username = "yourUserName";
  4. $password = "yourPassword";
  5. $dbname = "yourDatabaseName";
  6.  
  7. $conn = new mysqli($servername, $username, $password, $dbname);
  8. if ($conn->connect_error) {
  9. die("Connection failed: " . $conn->connect_error);
  10. }
  11.  
  12. $size = array(4,2,1);
  13.  
  14. $sql = "SELECT userName, userContact FROM Persons";
  15. $result = $conn->query($sql);
  16.  
  17. $response = array(
  18. "c2array" => true,
  19. "size" => $size,
  20. "data" => array()
  21. );
  22.  
  23. while ( $row = $result->fetch_assoc() ) {
  24. $response['data'][] = array(
  25. array($row['userName']),
  26. array($row['userContact'])
  27. );
  28. }
  29.  
  30. echo json_encode($response);
  31. $conn->close();
  32. exit();
  33. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement