sqlsrv_get_field

(사용 가능한 버전 정보가 없으며 Git에만 있을 수 있음)

sqlsrv_get_field — 현재 선택된 행에서 필드 데이터를 가져옵니다.

sqlsrv_get_field(resource $stmt, int $fieldIndex, int $getAsType = ?): mixed

현재 선택된 행에서 필드 데이터를 가져옵니다. 필드는 순서대로 액세스해야 합니다. 필드 인덱스는 0에서 시작합니다.


매개변수

stmt
sqlsrv_query() 또는 sqlsrv_execute()에서 반환된 명령문 리소스입니다.
fieldIndex
검색할 필드의 인덱스입니다. 필드 인덱스는 0에서 시작합니다. 필드는 순서대로 액세스해야 합니다. 즉, 필드 인덱스 1에 액세스하면 필드 인덱스 0을 사용할 수 없습니다.
getAsType
반환된 필드 데이터의 PHP 데이터 유형입니다. 이 매개변수를 설정하지 않으면 필드 데이터가 기본 PHP 데이터 유형으로 반환됩니다. 기본 PHP 데이터 유형에 대한 자세한 내용은 Microsoft SQLSRV 문서에서 » 기본 PHP 데이터 유형을 참조하세요.

반환 값

성공 시 지정된 필드의 데이터를 반환합니다. 그렇지 않으면 false를 반환합니다.


Examples

예제 #1 sqlsrv_get_field() 예제

다음 예는 sqlsrv_fetch()를 사용하여 행을 검색하고 sqlsrv_get_field()를 사용하여 행 필드를 가져오는 방법을 보여줍니다.

                  
<?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 Name, Comment
        FROM Table_1
        WHERE ReviewID=1";
$stmt = sqlsrv_query( $conn, $sql);
if( $stmt === false ) {
     die( print_r( sqlsrv_errors(), true));
}

// Make the first (and in this case, only) row of the result set available for reading.
if( sqlsrv_fetch( $stmt ) === false) {
     die( print_r( sqlsrv_errors(), true));
}

// Get the row fields. Field indices start at 0 and must be retrieved in order.
// Retrieving row fields by name is not supported by sqlsrv_get_field.
$name = sqlsrv_get_field( $stmt, 0);
echo "$name: ";

$comment = sqlsrv_get_field( $stmt, 1);
echo $comment;
?>
                  
                

기타