<?php
// Veritabanı bağlantısı
$con = mysqli_connect("localhost", "root", "", "kullanıcı");
// Bağlantı kontrolü
if (!$con) {
die("Veritabanı bağlantı hatası: " . mysqli_connect_error());
}
// HTTP isteğinden id parametresini alma
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
// SQL sorgusu
$sql = "SELECT * FROM kullanıcı WHERE ID = ?";
// Sorguyu hazırlama ve parametre bağlama
$stmt = mysqli_prepare($con, $sql);
mysqli_stmt_bind_param($stmt, "i", $id);
// Sorguyu çalıştırma
mysqli_stmt_execute($stmt);
// Sonuçları al
$result = mysqli_stmt_get_result($stmt);
// Veri varsa JSON olarak dön
if ($row = mysqli_fetch_assoc($result)) {
header("Content-Type: application/json");
echo json_encode($row, JSON_PRETTY_PRINT);
} else {
// Eğer sonuç yoksa, hata mesajı
echo json_encode(["error" => "Kayıt bulunamadı"]);
}
// Bağlantıyı kapat
mysqli_close($con);
?>