Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function my_sql($connection){
- $sql = "SELECT name, date, age, address FROM test_data";
- $rawdata = query($connection, $sql);
- $data = [];
- foreach($rawdata as $row){
- $obj = new stdClass();
- $obj->name = $row["name"];
- $obj->date = $row["date"];
- $obj->age = $row["age"];
- $data = $obj;
- }
- $output = array();
- $output["name"] = $name;
- $output["date"] = $date;
- $output["age"] = $age;
- return $output;
- }
- $sql_output = my_sql(connection);
- echo gettype($sql_output); // Making sure it is an array
- var_dump($sql_output); // Dump it to make sure it populated
- if(isset($sql_output)) {
- echo "Set";
- $json = json_encode($sql_output,JSON_PRETTY_PRINT);
- $fp = fopen('C:UserstjDesktopresults.json', 'w');
- fwrite($fp, $json);
- fclose($fp);
- } else {
- echo "Object Not Received";
- }
- ?>
Add Comment
Please, Sign In to add comment