array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'function.sqlsrv-num-fields.php', 1 => 'sqlsrv_num_fields', ), 'up' => array ( 0 => 'ref.sqlsrv.php', 1 => 'SQLSRV 関数', ), 'prev' => array ( 0 => 'function.sqlsrv-next-result.php', 1 => 'sqlsrv_next_result', ), 'next' => array ( 0 => 'function.sqlsrv-num-rows.php', 1 => 'sqlsrv_num_rows', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/sqlsrv/functions/sqlsrv-num-fields.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(No version information available, might only be in Git)
sqlsrv_num_fields — Retrieves the number of fields (columns) on a statement
Retrieves the number of fields (columns) on a statement.
stmt
The statement for which the number of fields is returned. sqlsrv_num_fields() can be called on a statement before or after statement execution.
Returns the number of fields on success. Returns false
otherwise.
例1 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 />";
}
?>