sqlsrv_fetch_array

(No version information available, might only be in Git)

sqlsrv_fetch_arrayReturns a row as an array

说明

sqlsrv_fetch_array ( resource $stmt [, int $fetchType [, int $row [, int $offset ]]] ) : array

Returns the next available row of data as an associative array, a numeric array, or both (the default).

参数

stmt

A statement resource returned by sqlsrv_query or sqlsrv_prepare.

fetchType

A predefined constant specifying the type of array to return. Possible values are SQLSRV_FETCH_ASSOC, SQLSRV_FETCH_NUMERIC, and SQLSRV_FETCH_BOTH (the default).

A fetch type of SQLSRV_FETCH_ASSOC should not be used when consuming a result set with multiple columns of the same name.

row

Specifies the row to access in a result set that uses a scrollable cursor. Possible values are SQLSRV_SCROLL_NEXT, SQLSRV_SCROLL_PRIOR, SQLSRV_SCROLL_FIRST, SQLSRV_SCROLL_LAST, SQLSRV_SCROLL_ABSOLUTE and, SQLSRV_SCROLL_RELATIVE (the default). When this parameter is specified, the fetchType must be explicitly defined.

offset

Specifies the row to be accessed if the row parameter is set to SQLSRV_SCROLL_ABSOLUTE or SQLSRV_SCROLL_RELATIVE. Note that the first row in a result set has index 0.

返回值

Returns an array on success, NULL if there are no more rows to return, and FALSE if an error occurs.

范例

Example #1 Retrieving an associative array.

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

$sql "SELECT FirstName, LastName FROM SomeTable";
$stmt sqlsrv_query$conn$sql );
if( 
$stmt === false) {
    die( 
print_rsqlsrv_errors(), true) );
}

while( 
$row sqlsrv_fetch_array$stmtSQLSRV_FETCH_ASSOC) ) {
      echo 
$row['LastName'].", ".$row['FirstName']."<br />";
}

sqlsrv_free_stmt$stmt);
?>

Example #2 Retrieving a numeric array.

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

$sql "SELECT FirstName, LastName FROM SomeTable";
$stmt sqlsrv_query$conn$sql );
if( 
$stmt === false) {
    die( 
print_rsqlsrv_errors(), true) );
}

while( 
$row sqlsrv_fetch_array$stmtSQLSRV_FETCH_NUMERIC) ) {
      echo 
$row[0].", ".$row[1]."<br />";
}

sqlsrv_free_stmt$stmt);
?>

注释

Not specifying the fetchType or explicitly using the SQLSRV_FETCH_TYPE constant in the examples above will return an array that has both associative and numeric keys.

If more than one column is returned with the same name, the last column will take precedence. To avoid field name collisions, use aliases.

If a column with no name is returned, the associative key for the array element will be an empty string ("").

参见

相关文章
php cubrid mysql 兼容性函数 return the associative array that corresponds to the fetched rowphp date/time 函数 returns associative array with detailed info about given datephp ibm db2 函数 returns an array indexed by column position representing a row in a result setphp ibm db2 函数 returns an array indexed by column name representing a row in a result setphp ibm db2 函数 returns an array indexed by both column name and position representing a row in a result setphp frontbase 函数 fetch a result row as an associative arrayphp mailparse 函数 returns an array of mime section names in the supplied messagephp maxdb 函数 fetch a result row as an associative a numeric array or bothphp mssql 函数 returns an associative array of the current row in the resultphp mysqlnd ms 函数 returns an array which describes the last used connectionphp oci8 函数 returns the next row from a query as an associative or numeric arrayphp oci8 函数 returns the next row from a query as an associative arrayphp oci8 函数 returns the next row from a query as a numeric arrayphp sqlite 函数 fetches the current row from a result set as an arrayphp sqlite 函数 returns the current row indexphp sqlite 函数 returns the rowid of the most recently inserted rowphp sqlite 函数 executes a query and returns either an array for one single column or the value of the first rowphp sqlsrv 函数 returns a row as an arrayphp sqlsrv 函数 returns the value of the specified configuration settingphp sqlsrv 函数 gets field data from the currently selected row
关注编程学问公众号