PHP mysqli multi_query() လုပ်ဆောင်ချက်
ဥပမာ - Object Oriented စတိုင်
ဒေတာဘေ့စကို ဆန့်ကျင်သည့် မေးခွန်းများစွာကို လုပ်ဆောင်ပါ-
<?php
$mysqli = new mysqli("localhost","my_user","my_password","my_db");
if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}
$sql = "SELECT Lastname FROM Persons ORDER BY LastName;";
$sql .= "SELECT Country FROM Customers";
// Execute multi query
if ($mysqli
-> multi_query($sql)) {
do {
// Store first result set
if ($result =
$mysqli -> store_result()) {
while ($row =
$result -> fetch_row()) {
printf("%s\n", $row[0]);
}
$result
-> free_result();
}
// if there are more result-sets, the print a
divider
if ($mysqli -> more_results()) {
printf("-------------\n");
}
//Prepare next result set
} while ($mysqli
-> next_result());
}
$mysqli -> close();
?>
အောက်ခြေတွင် လုပ်ထုံးလုပ်နည်းပုံစံ နမူနာကိုကြည့်ပါ။
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
multi_query() / mysqli_multi_query() လုပ်ဆောင်ချက်သည် ဒေတာဘေ့စ်နှင့် ဆန့်ကျင်ဘက်တစ်ခု သို့မဟုတ် တစ်ခုထက်ပိုသော မေးခွန်းများကို လုပ်ဆောင်သည်။ မေးခွန်းများကို semicolon ဖြင့် ခွဲခြားထားသည်။
အထားအသို
အရာဝတ္ထုကို ဦးတည်သည့်ပုံစံ-
$mysqli ->
multi_query(query)
လုပ်ထုံးလုပ်နည်းပုံစံ-
mysqli_multi_query(connection, query)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
connection | Required. Specifies the MySQL connection to use |
query | Required. Specifies one or more queries, separated with semicolon |
နည်းပညာဆိုင်ရာအသေးစိတ်
ပြန်ပို့တန်ဖိုး- | ပထမမေးမြန်းချက် မအောင်မြင်ပါက မှားပါ။ |
---|---|
PHP ဗားရှင်း- | ၅+ |
ဥပမာ- လုပ်ထုံးလုပ်နည်းပုံစံ
ဒေတာဘေ့စကို ဆန့်ကျင်သည့် မေးခွန်းများစွာကို လုပ်ဆောင်ပါ-
<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
$sql = "SELECT Lastname FROM Persons ORDER BY LastName;";
$sql .= "SELECT Country FROM Customers";
// Execute multi query
if (mysqli_multi_query($con, $sql)) {
do {
// Store first result set
if ($result = mysqli_store_result($con)) {
while ($row = mysqli_fetch_row($result)) {
printf("%s\n", $row[0]);
}
mysqli_free_result($result);
}
// if there are more result-sets, the print a
divider
if (mysqli_more_results($con)) {
printf("-------------\n");
}
//Prepare next result set
} while (mysqli_next_result($con));
}
mysqli_close($con);
?>
❮ PHP MySQLi အကိုးအကား