PHP.mk документација

sqlsrv_fetch_object

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.sqlsrv-fetch-object.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.sqlsrv-fetch-object.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
sqlsrv_fetch_object

Референца за `function.sqlsrv-fetch-object.php` со подобрена типографија и навигација.

function.sqlsrv-fetch-object.php

sqlsrv_fetch_object

(Нема достапни информации за верзијата, можеби е само во Git)

sqlsrv_fetch_objectRetrieves the next row of data in a result set as an object

= NULL

sqlsrv_fetch_object(
         resource $stmt,
         string $className = ?,
         array $ctorParams = ?,
         int $row = ?,
         int $offset = ?
): mixed

Retrieves the next row of data in a result set as an instance of the specified class with properties that match the row field names and values that correspond to the row field values.

Параметри

stmt
A statement resource created by sqlsrv_query() or sqlsrv_execute().
className
The name of the class to instantiate. If no class name is specified, stdClass is instantiated.
ctorParams
Values passed to the constructor of the specified class. If the constructor of the specified class takes parameters, the ctorParams array must be supplied.
row

Редот до кој ќе се пристапи. Овој параметар може да се користи само ако наведената изјава е подготвена со курсор што може да се скрола. Во тој случак, овој параметар може да ги земе следниве вредности:

  • SQLSRV_SCROLL_NEXT
  • SQLSRV_SCROLL_PRIOR
  • SQLSRV_SCROLL_FIRST
  • SQLSRV_SCROLL_LAST
  • SQLSRV_SCROLL_ABSOLUTE
  • SQLSRV_SCROLL_RELATIVE
offset
мора експлицитно да се дефинира. SQLSRV_SCROLL_ABSOLUTE or SQLSRV_SCROLL_RELATIVEСпецифицира ред што треба да се пристапи ако параметарот ред е поставен на

Вратени вредности

Returns an object on success, null Враќа низа при успех, false if an error occurs or if the specified class does not exist.

Примери

Пример #1 sqlsrv_fetch_object() example

The following example demonstrates how to retrieve a row as a stdClass object.

<?php
$serverName
= "serverName\sqlexpress";
$connectionInfo = array( "Database"=>"dbName", "UID"=>"username", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if(
$conn === false ) {
die(
print_r( sqlsrv_errors(), true));
}

$sql = "SELECT fName, lName FROM Table_1";
$stmt = sqlsrv_query( $conn, $sql);
if(
$stmt === false ) {
die(
print_r( sqlsrv_errors(), true));
}

// Retrieve each row as an object.
// Because no class is specified, each row will be retrieved as a stdClass object.
// Property names correspond to field names.
while( $obj = sqlsrv_fetch_object( $stmt)) {
echo
$obj->fName.", ".$obj->lName."<br />";
}
?>

Белешки

If a class name is specified with the optional $className parameter and the class has properties whose names match the result set field names, the corresponding result set values are applied to the properties. If a result set field name does not match a class property, a property with the result set field name is added to the object and the result set value is applied to the property. The following rules apply when using the $className parameter:

  • Field-property name matching is case-sensitive.
  • Field-property matching occurs regardless of access modifiers.
  • Class property data types are ignored when applying a field value to a property.
  • If the class does not exist, the function returns false and adds an error to the error collection.
Regardless of whether the $className parameter is supplied, if a field with no name is returned, the field value will be ignored and a warning will be added to the error collection.

When consuming a result set that has multiple columns with the same name, it may be better to use sqlsrv_fetch_array() or the combination of sqlsrv_fetch() and sqlsrv_get_field().

Види Исто така

  • sqlsrv_fetch() - Го прави следниот ред во множеството резултати достапен за читање
  • sqlsrv_fetch_array() - Враќа ред како низа

Белешки од корисници

Нема белешки од корисници за оваа страница.
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.