Funkce PHP mysqli fetch_row().
Příklad - Objektově orientovaný styl
Načíst řádky ze sady výsledků:
<?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, Age FROM Persons ORDER BY Lastname";
if ($result = $mysqli -> query($sql)) {
while ($row = $result -> fetch_row()) {
printf ("%s (%s)\n", $row[0], $row[1]);
}
$result
-> free_result();
}
$mysqli -> close();
?>
Podívejte se na příklad procedurálního stylu dole.
Definice a použití
Funkce fetch_row() / mysqli_fetch_row() načte jeden řádek ze sady výsledků a vrátí jej jako výčtové pole.
Syntax
Objektově orientovaný styl:
$mysqli_result -> fetch_row()
Styl postupu:
mysqli_fetch_row(result)
Hodnoty parametrů
Parameter | Description |
---|---|
result | Required. Specifies a result set identifier returned by mysqli_query(), mysqli_store_result() or mysqli_use_result() |
Technické údaje
Návratová hodnota: | Vrátí pole řetězců, které odpovídá načtenému řádku. NULL, pokud v sadě výsledků nejsou žádné další řádky |
---|---|
Verze PHP: | 5+ |
Příklad - Procedurální styl
Načíst řádky ze sady výsledků:
<?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, Age FROM Persons ORDER BY Lastname";
if ($result = mysqli_query($con, $sql)) {
// Fetch one and one row
while ($row = mysqli_fetch_row($result)) {
printf ("%s (%s)\n", $row[0], $row[1]);
}
mysqli_free_result($result);
}
mysqli_close($con);
?>
❮ Reference PHP MySQLi