sqlsrv_num_fields

(No version information available, might only be in Git)
Retrieves the number of fields (columns) on a statement
mixed sqlsrv_num_fields ( resource $stmt )

Retrieves the number of fields (columns) on a statement.

Parameters:
stmt

The statment for which the number of fields is returned. sqlsrv_num_fields() can be called on a statement before or after statement execution.

Returns:

Returns the number of fields on success. Returns FALSE otherwise.

Examples:
sqlsrv_num_fields() example
<?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 * FROM Table_1";
$stmt = sqlsrv_query($conn, $sql);
if( $stmt === false) {
   die( print_r( sqlsrv_errors(), true));
}

$numFields = sqlsrv_num_fields( $stmt );

while( sqlsrv_fetch( $stmt )) {
   // Iterate through the fields of each row.
   for($i = 0; $i < $numFields; $i++) { 
      echo sqlsrv_get_field($stmt, $i)." ";
   }
   echo "<br />";
}
?>

See also:

sqlsrv_field_metadata() -

sqlsrv_fetch() -

sqlsrv_get_field() -

doc_php
2016-02-24 16:18:41
Comments
Leave a Comment

Please login to continue.