Mssql 函数
PHP Manual

mssql_fetch_field

(PHP 4, PHP 5, PECL odbtp >= 1.1.1)

mssql_fetch_fieldGet field information

Warning

This function was REMOVED in PHP 7.0.0.

Alternatives to this function include:

说明

object mssql_fetch_field ( resource $result [, int $field_offset = -1 ] )

mssql_fetch_field() can be used in order to obtain information about fields in a certain query result.

参数

result

The result resource that is being evaluated. This result comes from a call to mssql_query().

field_offset

The numerical field offset. If the field offset is not specified, the next field that was not yet retrieved by this function is retrieved. The field_offset starts at 0.

返回值

Returns an object containing field information.

The properties of the object are:

范例

Example #1 mssql_fetch_field() example

<?php
// Connect to MSSQL and select the database
mssql_connect('MANGO\SQLEXPRESS''sa''phpfi');
mssql_select_db('php');

// Send a select query to MSSQL
$query mssql_query('SELECT * FROM [php].[dbo].[persons]');

// Construct table
echo '<h3>Table structure for \'persons\'</h3>';
echo 
'<table border="1">';

// Table header
echo '<thead>';
echo 
'<tr>';
echo 
'<td>Field name</td>';
echo 
'<td>Data type</td>';
echo 
'<td>Max length</td>';
echo 
'</tr>';
echo 
'</thead>';

// Dump all fields
echo '<tbody>';

for (
$i 0$i mssql_num_fields($query); ++$i) {
    
// Fetch the field information
    
$field mssql_fetch_field($query$i);

    
// Print the row
    
echo '<tr>';
    echo 
'<td>' $field->name '</td>';
    echo 
'<td>' strtoupper($field->type) . '</td>';
    echo 
'<td>' $field->max_length '</td>';
    echo 
'</tr>';
}

echo 
'</tbody>';
echo 
'</table>';

// Free the query result
mssql_free_result($query);
?>

参见


Mssql 函数
PHP Manual