<?php

require_once "conn.php";

$stmt = $conn->prepare("SELECT id, nama, sex, tanggallahir, alamat_sekarang, foto FROM tweb_penduduk;");

$stmt->execute();
$stmt->bind_result($id, $nama, $kelamin, $tanggal, $alamat, $foto);

$penduduk = array();

while($stmt->fetch()){
    $temp = array();
    $temp['id'] = $id;
    $temp['nama'] = $nama;
    $temp['kelamin'] = $kelamin;
    $temp['tanggal'] = $tanggal;
    $temp['alamat'] = $alamat;
    $temp['foto'] = $foto;
    

    array_push($penduduk, $temp);
}

echo json_encode($penduduk);