Guest User

Untitled

a guest
Jun 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. <?php
  2.  
  3. function my_sql($connection){
  4. $sql = "SELECT name, date, age, address FROM test_data";
  5. $rawdata = query($connection, $sql);
  6. $data = [];
  7. foreach($rawdata as $row){
  8. $obj = new stdClass();
  9. $obj->name = $row["name"];
  10. $obj->date = $row["date"];
  11. $obj->age = $row["age"];
  12. $data = $obj;
  13. }
  14. $output = array();
  15. $output["name"] = $name;
  16. $output["date"] = $date;
  17. $output["age"] = $age;
  18. return $output;
  19. }
  20.  
  21. $sql_output = my_sql(connection);
  22. echo gettype($sql_output); // Making sure it is an array
  23. var_dump($sql_output); // Dump it to make sure it populated
  24. if(isset($sql_output)) {
  25. echo "Set";
  26. $json = json_encode($sql_output,JSON_PRETTY_PRINT);
  27. $fp = fopen('C:UserstjDesktopresults.json', 'w');
  28. fwrite($fp, $json);
  29. fclose($fp);
  30. } else {
  31. echo "Object Not Received";
  32. }
  33. ?>
Add Comment
Please, Sign In to add comment