Thuta Learning
ရှာဖွေရန်
AdvancedProgrammingbeginner

SELECT Data

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

SELECT query ကို database ထဲက data ဖတ်ဖို့သုံးပါတယ်။ Product list, blog posts, user table, contact messages စတာတွေကိုပြချင်ရင် SELECT လိုပါတယ်။ User input ပါတဲ့ SELECT query တွေမှာ prepared statement သုံးပါ။

php
<?php
$searchEmail = "user@example.com";

$stmt = $conn->prepare("SELECT id, name, email FROM contacts WHERE email = ?");
$stmt->bind_param("s", $searchEmail);
$stmt->execute();
$result = $stmt->get_result();

while ($row = $result->fetch_assoc()) {
  echo htmlspecialchars($row["name"]) . " - " . htmlspecialchars($row["email"]) . "<br>";
}

$stmt->close();
?>
You should see
Email ကိုက်ညီသော contact record များကို name - email format ဖြင့်ပြမည်။

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • User input ကို SQL string ထဲတိုက်ရိုက်ထည့်တာက SQL injection ဖြစ်စေနိုင်ပါတယ်။
SELECT Data | Thuta Learning