PHP – MySQL to JSON

Script ke-1

<?php 
 $db_host = "localhost";
 $db_user = "root";
 $db_pass = "12345678";
 $db_name = "cerita";
 $koneksi = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
 $sql = "Select id_artikel, judul, deskripsi, id_kategori from artikel";
 $query = mysqli_query($koneksi, $sql);
 $rows=array();
 while($data = mysqli_fetch_assoc($query)){
 $rows[] = $data;
 $rows[] = "<br>";
 }
 echo json_encode($rows);
?>

Script ke-2

<?php 
 $db_host = "localhost";
 $db_user = "root";
 $db_pass = "12345678";
 $db_name = "cerita";
 $koneksi = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
 $kat = $_GET["kat"];
 $sql = "Select id_artikel, judul, deskripsi, id_kategori 
         from artikel where id_kategori='$kat'";
 $query = mysqli_query($koneksi, $sql);
 $rows=array();
 while($data = mysqli_fetch_assoc($query)){
 $rows[] = $data;
 $rows[] = "<br>";
 }
 echo json_encode($rows);
?>