준비된 문의 필드에 대한 메타데이터를 검색합니다. 문을 준비하는 방법은 sqlsrv_query 또는 sqlsrv_prepare를 참조하십시오. 실행 전이나 실행 후에 준비된 문에서 sqlsrv_field_metadata를 호출할 수 있습니다.
구문
sqlsrv_field_metadata( resource $stmt)
매개 변수
$stmt: 필드 메타데이터가 검색된 문 리소스입니다.
반환 값
배열의 array 또는 false입니다. 배열은 결과 집합의 각 필드마다 하나의 배열로 구성됩니다. 각 하위 배열에는 아래 표에 설명된 키가 있습니다. 필드 메타데이터를 검색할 때 오류가 발생하면 false가 반환됩니다.
| 키 | 설명 |
|---|---|
이름 |
필드가 해당하는 열의 이름입니다. |
형식 |
SQL 형식에 해당하는 숫자 값입니다. |
크기 |
문자 유형(char(n), varchar(n), nchar(n), nvarchar(n), XML) 필드에 대한 문자 수입니다. 이진 유형(binary(n), varbinary(n), UDT) 필드에 대한 바이트 수입니다. 다른 SQL Server 데이터 형식의 경우에는 NULL입니다. |
전체 자릿수 |
가변 전체 자릿수를 가지는 형식(real, numeric, decimal, datetime2, datetimeoffset, time)의 전체 자릿수입니다. SQL Server 데이터 형식의 경우에는 NULL입니다. |
소수 자릿수 |
가변 소수 자릿수를 가지는 형식(numeric, decimal, datetime2, datetimeoffset, and time)의 소수 자릿수입니다. SQL Server 데이터 형식의 경우에는 NULL입니다. |
Null 허용 |
null이 허용되는 열인지(SQLSRV_NULLABLE_YES), null이 허용되지 않는 열인지(SQLSRV_NULLABLE_NO) 또는 null이 허용되는지 여부를 알 수 없는지(SQLSRV_NULLABLE_UNKNOWN)를 나타내는 열거형 값입니다. |
다음 표에는 각 하위 배열에 대한 자세한 키 정보가 나와 있습니다. 이러한 형식에 대한 자세한 내용은 SQL Server 설명서를 참조하십시오.
| SQL Server 2008 데이터 형식 | 형식 | Min/Max Precision | Min/Max Scale | 크기 |
|---|---|---|---|---|
bigint |
-5 |
8 |
||
binary |
-2 |
0 < n < 8000 1 |
||
bit |
-7 |
|||
char |
1 |
0 < n < 8000 1 |
||
date |
91 |
10/10 |
0/0 |
|
datetime |
93 |
23/23 |
3/3 |
|
datetime2 |
93 |
19/27 |
0/7 |
|
datetimeoffset |
-155 |
26/34 |
0/7 |
|
decimal |
3 |
1/38 |
0/전체 자릿수 값 |
|
float |
6 |
4/8 |
||
image |
-4 |
2GB |
||
int |
4 |
|||
money |
3 |
19/19 |
4/4 |
|
nchar |
-8 |
0 < n < 4000 1 |
||
ntext |
-10 |
1GB |
||
numeric |
2 |
1/38 |
0/전체 자릿수 값 |
|
nvarchar |
-9 |
0 < n < 4000 1 |
||
real |
7 |
4/4 |
||
smalldatetime |
93 |
16/16 |
0/0 |
|
smallint |
5 |
2 bytes |
||
smallmoney |
3 |
10/10 |
4/4 |
|
text |
-1 |
2GB |
||
time |
-154 |
8/16 |
0/7 |
|
timestamp |
-2 |
8바이트 |
||
tinyint |
-6 |
1바이트 |
||
udt |
-151 |
variable |
||
uniqueidentifier |
-11 |
16 |
||
varbinary |
-3 |
0 < n < 8000 1 |
||
varchar |
12 |
0 < n < 8000 1 |
||
xml |
-152 |
0 |
(1) 영(0)은 최대 크기가 허용됨을 나타냅니다.
Null을 허용하는 키는 yes 또는 no가 될 수 있습니다.
예
다음 예제에서는 문 리소스를 만든 다음 필드 메타데이터를 검색하여 표시합니다. SQL Server와 AdventureWorks 데이터베이스가 로컬 컴퓨터에 설치되어 있다고 가정합니다. 명령줄에서 이 예제를 실행하면 모든 출력이 콘솔에 기록됩니다.
<?php
/* Connect to the local server using Windows Authentication and
specify the AdventureWorks database as the database in use. */
$serverName = "(local)";
$connectionInfo = array( "Database"=>"AdventureWorks");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
echo "Could not connect.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Prepare the statement. */
$tsql = "SELECT ReviewerName, Comments FROM Production.ProductReview";
$stmt = sqlsrv_prepare( $conn, $tsql);
/* Get and display field metadata. */
foreach( sqlsrv_field_metadata( $stmt) as $fieldMetadata)
{
foreach( $fieldMetadata as $name => $value)
{
echo "$name: $value\n";
}
echo "\n";
}
/* Note: sqlsrv_field_metadata can be called on any statement
resource, pre- or post-execution. */
/* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
?>