PHP mysqli query() လုပ်ဆောင်ချက်
ဥပမာ - Object Oriented စတိုင်
ဒေတာဘေ့စ်တစ်ခုနှင့် ပတ်သက်၍ မေးမြန်းမှုကို လုပ်ဆောင်ပါ-
<?php
$mysqli = new mysqli("localhost","my_user","my_password","my_db");
// Check connection
if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}
// Perform query
if ($result = $mysqli -> query("SELECT * FROM Persons"))
{
echo "Returned rows are: " . $result -> num_rows;
// Free result set
$result -> free_result();
}
$mysqli -> close();
?>
အောက်ခြေတွင် လုပ်ထုံးလုပ်နည်းပုံစံ နမူနာကိုကြည့်ပါ။
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
query() / mysqli_query() လုပ်ဆောင်ချက်သည် ဒေတာဘေ့စ်တစ်ခုအား စုံစမ်းမေးမြန်းမှုကို လုပ်ဆောင်သည်။
အထားအသို
အရာဝတ္ထုကို ဦးတည်သည့်ပုံစံ-
$mysqli -> query(query,
resultmode)
လုပ်ထုံးလုပ်နည်းပုံစံ-
mysqli_query(connection, query, resultmode)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
connection | Required. Specifies the MySQL connection to use |
query | Required. Specifies the SQL query string |
resultmode |
Optional. A constant. Can be one of the following:
|
နည်းပညာဆိုင်ရာအသေးစိတ်
ပြန်ပို့တန်ဖိုး- | အောင်မြင်သော SELECT၊ SHOW၊ DESCRIBE သို့မဟုတ် EXPLAIN မေးခွန်းများအတွက် ၎င်းသည် mysqli_result အရာဝတ္ထုကို ပြန်ပေးလိမ့်မည်။ အခြားအောင်မြင်သောမေးခွန်းများအတွက် ၎င်းသည် TRUE ပြန်လာပါမည်။ ရှုံးနိမ့်မှုအပေါ် မှားသည်။ |
---|---|
PHP ဗားရှင်း- | ၅+ |
PHP Changelog- | PHP 5.3.0 သည် async queries များအတွက် စွမ်းရည်ကို ထည့်သွင်းထားသည်။ |
ဥပမာ- လုပ်ထုံးလုပ်နည်းပုံစံ
ဒေတာဘေ့စ်တစ်ခုနှင့် ပတ်သက်၍ မေးမြန်းမှုကို လုပ်ဆောင်ပါ-
<?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();
}
// Perform query
if ($result = mysqli_query($con, "SELECT * FROM Persons"))
{
echo "Returned rows are: " . mysqli_num_rows($result);
// Free result set
mysqli_free_result($result);
}
mysqli_close($con);
?>
❮ PHP MySQLi အကိုးအကား