setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES,false); $sql = 'select idd, nama_depan, nama_belakang, alamat_tinggal from tentang '; $stmt = $pdo->prepare($sql); $stmt->execute(); $data = []; while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $data[] = $row; } $response = []; $response['data'] = $data; echo json_encode($response, JSON_PRETTY_PRINT); } catch (PDOException $e) { echo 'Database error. ' . $e->getMessage(); }