(PHP 5, PHP 7)
mysqli_result::fetch_object -- mysqli_fetch_object — Returns the current row of a result set as an object
Nesne yönelimli kullanım
$class
= "stdClass"
, array $constructor_args
= []
) : object|null|falseYordamsal kullanım
$result
, string $class
= "stdClass"
, array $constructor_args
= []
) : object|null|falseReturns the current row result set as an object where the attributes of the object represent the names of the fields found within the result set.
Bilginize: This function sets the properties of the object before calling the object constructor.
Bilginize: Bu işlevden dönen alan isimlerinin harf büyüklüklerinde değişiklik yapılmaz.
Bilginize: Bu işlev NULL alanlara PHP
null
değerini atar.
sonuç
Sadece yordamsal tarz: mysqli_query(), mysqli_store_result() veya mysqli_use_result() işlevinden dönen bir sonuç kümesi tanıtıcısı.
class
The name of the class to instantiate, set the properties of and return. If not specified, a stdClass object is returned.
constructor_args
An optional array of parameters to pass to the constructor
for class
objects.
Returns an object that corresponds to the fetched
row or null
if there are no more rows in result set.
Sürüm: | Açıklama |
---|---|
8.0.0 |
constructor_args now accepts [] for constructors with 0 parameters;
previously an exception was thrown.
|
Örnek 1 mysqli_result::fetch_object() example
Nesne yönelimli kullanım
<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
$query = "SELECT Name, CountryCode FROM City ORDER BY ID DESC";
$result = $mysqli->query($query);
/* fetch object array */
while ($obj = $result->fetch_object()) {
printf("%s (%s)\n", $obj->Name, $obj->CountryCode);
}
Yordamsal kullanım
<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
$query = "SELECT Name, CountryCode FROM City ORDER BY ID DESC";
$result = mysqli_query($link, $query);
/* fetch associative array */
while ($obj = mysqli_fetch_object($result)) {
printf("%s (%s)\n", $obj->Name, $obj->CountryCode);
}
The above examples will output something similar to:
Pueblo (USA) Arvada (USA) Cape Coral (USA) Green Bay (USA) Santa Clara (USA)