MySQLI_Prepare () SQL ကြေ ငြာ ချက်ကိုပြင်ဆင်ရန်အသုံးပြုသည်။ ဥပမာအားဖြင့်:
$mysqli = new mysqli("m66.net", "username", "password", "database");
if ($mysqli->connect_error) {
die("ဆက်သွယ်မှုမအောင်မြင်ပါ: " . $mysqli->connect_error);
}
$sql = "SELECT * FROM users WHERE email = ?";
$stmt = $mysqli->prepare($sql);
if (!$stmt) {
die("Preprocessing မအောင်မြင်ပါ: " . $mysqli->error);
}
ဒီမှာ, ? parameter သည် placeholder သည် place ာရှယ်ယာပိုင်ရှင်ဖြစ်ပြီးတိကျသောတန်ဖိုးသည်အနာဂတ်တွင် bind_param မှတဆင့်ချည်နှောင်ထားလိမ့်မည်။
MySQLI_STMT အရာဝတ်ထုသည်အချို့သောဂုဏ်သတ္တိများကိုရယူခြင်း, PHP သည်ဆက်စပ်သောနည်းလမ်းနှစ်ခုကိုထောက်ပံ့ပေးသည်။
Att_get ($ attr) - သတ်မှတ်ထားသော attribute ၏လက်ရှိတန်ဖိုးကိုရရှိသည်။
Att_set ($ Attach, $ တန်ဖိုး) - သတ်မှတ်ထားသော attribute ၏တန်ဖိုးကိုသတ်မှတ်သည်။
ဥပမာ MySQLI မှထောက်ပံ့သော attribute contivity များမှာ -
MySQLI_STMT_ATTR_APAX_Length : အများဆုံးအရှည်ကို update လုပ်မထား,
MySQLI_STMT_ATTR_CARSOR_TYPE : Cursor type (ဥပမာ cursor, ဖတ်ခြင်း, ဖတ်ခြင်း,
MySQLI_STMT_ATTR_ROWS : Premetched အတန်းအရေအတွက်။
အချက်အလက်အမြောက်အများကိုလုပ်ဆောင်ရန် cursors များကိုအသုံးပြုလိုပြီးရလဒ်အားလုံးကိုတင်ရန်ရှောင်ကြဉ်လိုပါက Cursor Properties များကိုသတ်မှတ်နိုင်သည်။
$sql = "SELECT * FROM large_table WHERE category = ?";
$stmt = $mysqli->prepare($sql);
if (!$stmt) {
die("Preprocessing မအောင်မြင်ပါ: " . $mysqli->error);
}
// cursor type ကိုရန် MYSQLI_CURSOR_TYPE_READ_ONLY
$stmt->attr_set(MYSQLI_STMT_ATTR_CURSOR_TYPE, MYSQLI_CURSOR_TYPE_READ_ONLY);
// parameters တွေကိုချည်ထား
$category = 'books';
$stmt->bind_param("s", $category);
$stmt->execute();
// လက်ရှိ cursor အမျိုးအစားကိုရယူပါ
$currentCursorType = $stmt->attr_get(MYSQLI_STMT_ATTR_CURSOR_TYPE);
echo "လက်ရှိ cursor အမျိုးအစားဖြစ်ပါတယ်: " . $currentCursorType . PHP_EOL;
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
print_r($row);
}
$stmt->close();
$mysqli->close();
အထက်ပါဥပမာသည်ကြေငြာချက်ကိုပြင်ဆင်ခြင်းနှင့် attr_et () နှင့်လက်ရှိ attribute ကိုအတည်ပြုပြီးနောက် cursor အမျိုးအစားကိုမည်သို့သတ်မှတ်ရမည်ကိုပြသသည်။
execute လုပ်ခြင်းမပြုမီ () , လိုအပ်သောဂုဏ်သတ္တိများအားလုံးကို cursor type,
preprocessing နှင့် propertys settings နှစ်ခုလုံးကျရှုံးလိမ့်မည်။ running-time crashes ကိုရှောင်ရှားရန်ပြန်လည်ထူထောင်ရေးတန်ဖိုးကိုရှာဖွေရန်နှင့်အမှားအယွင်းများကိုကောင်းစွာကိုင်တွယ်ရန်သေချာပါစေ။
cursor အမျိုးအစားများသည်မှတ်ဥာဏ်နှင့်စွမ်းဆောင်ရည်ကိုသက်ရောက်မှုရှိသည်။ အထူးသဖြင့်ရလဒ်ကောင်းများနှင့်စပ်လျဉ်း။ စာဖတ်ခြင်းတစ်ခုတည်းသော cursors ( mySqli_cursor_type_Rype_Rype_read_only ) သည်များသောအားဖြင့်ပိုမိုကောင်းမွန်သောရွေးချယ်မှုဖြစ်သည်။
အချို့သောဂုဏ်သတ္တိများသည် MySQL ဆာဗာများသို့မဟုတ် PHP ဗားရှင်းများ၏အဟောင်းများနှင့်အဟောင်းများအဟောင်းများပေါ်တွင်မထောက်ပံ့နိုင်ပါ။ ဖွံ့ဖြိုးတိုးတက်မှုကာလအတွင်းပစ်မှတ်ပတ်ဝန်းကျင်၏ပံ့ပိုးမှုကိုသင်အတည်ပြုရမည်။
ကျိုးကြောင်းဆီလျော်သော mysqli_prepare () , mysqli_stmt :: AttR_Get နှင့် attr_et_set သည်သင်၏ကုဒ်၏လုံခြုံရေးကိုထိန်းသိမ်းထားစဉ်သင်၏ဒေတာဘေ့စ်စစ်ဆင်ရေးကိုပိုမိုပြောင်းလွယ်ပြင်လွယ်။ ထိရောက်စေသည်။ သင့်လျော်သောဂုဏ်သတ္တိများကိုသတ်မှတ်ခြင်းအားဖြင့်အထူးသဖြင့် cursors နှင့် prefetched stroped row tropage များ, စွမ်းဆောင်ရည်အရေအတွက်, စွမ်းဆောင်ရည်နှင့်အရင်းအမြစ်အသုံးပြုမှုကိုသိသိသာသာပိုမိုကောင်းမွန်အောင်ပြုလုပ်နိုင်သည်။