PHP mysqli use_result() Funksie
Voorbeeld - Objekgeoriënteerde styl
Inisieer die herwinning van 'n resultaatstel vanaf die laaste navraag wat uitgevoer is:
<?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 -> use_result()) {
while ($row =
$result -> fetch_row()) {
printf("%s\n", $row[0]);
}
$result
-> close();
}
// 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();
?>
Kyk na voorbeeld van prosedurele styl onderaan.
Definisie en gebruik
Die use_result() / mysqli_use_result() funksie begin die herwinning van 'n resultaatstel van die laaste navraag wat uitgevoer is.
Sintaksis
Objekgeoriënteerde styl:
$mysqli -> use_result()
Prosedure styl:
mysqli_use_result(connection)
Parameterwaardes
Parameter | Description |
---|---|
connection | Required. Specifies the MySQL connection to use |
Tegniese besonderhede
Terugkeerwaarde: | Wys 'n ongebufferde resultaatvoorwerp. ONWAAR op fout |
---|---|
PHP weergawe: | 5+ |
Voorbeeld - Prosedurele styl
Inisieer die herwinning van 'n resultaatstel vanaf die laaste navraag wat uitgevoer is:
<?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_use_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-verwysing