fork download
  1. <?php
  2. //connect to the local database.
  3. $link = mysql_connect('localhost','root', '');
  4.  
  5. //check to connect to test database
  6. $db_selected = mysql_select_db('test', $link);
  7.  
  8. //do select query.
  9. $result = mysql_query('SELECT userName,password,name,accountType from user');
  10.  
  11. //generate user array;
  12. while ($data = mysql_fetch_array($result)) {
  13. $user[] = array(
  14. 'userName' => $data['userName']
  15. ,'password' => $data['password']
  16. ,'name' => $data['name']
  17. ,'accountType'=> $data['accountType']
  18. );
  19. }
  20. //close the connection of localhost;
  21. $close_flag = mysql_close($link);
  22.  
  23. //encode user array to JASON;
  24. $json = json_encode($user);
  25. echo $json;
  26. ?>
Runtime error #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Standard output is empty