Guest User

Untitled

a guest
Jan 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. <?php
  2. function get_data(){
  3.  
  4. $connect = mysqli_connect("localhost", "root", "", "videos");
  5. $query = "SELECT * FROM `tb_indice`";
  6. $result = mysqli_query($connect, $query);
  7. $data = array();
  8. while($row = mysqli_fetch_array($result)){
  9.  
  10. $data[] = array(
  11. 'id' => $row["id"],
  12. 'titulo' => $row["titulo"],
  13. 'video' => $row["video"],
  14.  
  15. );
  16. }
  17. return json_encode($data);
  18. }
  19.  
  20. $file_name = date('d-m-Y') . '.json';
  21. if(file_put_contents($file_name, get_data())){
  22. echo $file_name . 'Arquivo criado';
  23. } else {
  24. echo "Ocorreu algum erro na criação do arquivo .json";
  25. }
  26.  
  27. $json = file_get_contents('http://localhost/01/20-01-2018.json');
  28. $data = json_decode($json);
Add Comment
Please, Sign In to add comment