伍佰目录 短网址
  当前位置:海洋目录网 » 站长资讯 » 站长资讯 » 文章详细 订阅RssFeed

PHP - Manual: mssql_field_name

来源:网络转载 浏览:49次 时间:2023-07-04
mssql_field_seek » « mssql_field_length PHP 手册 函数参考 数据库扩展 针对各数据库系统对应的扩展 Mssql Mssql 函数

mssql_field_name

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

mssql_field_name — Get the name of a field

Warning

This function was REMOVED in PHP 7.0.0.

Alternatives to this function include:

PDOStatement::getColumnMeta() sqlsrv_field_metadata() odbc_field_name()

说明

mssql_field_name ( resource $result [, int $offset = -1 ] ) : string

Returns the name of field no. offset in result.

参数

result

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

offset

The field offset, starts at 0. If omitted, the current field is used.

返回值

The name of the specified field index on success 或者在失败时返回 FALSE.

范例

Example #1 mssql_field_name() example

<?php
// Send a select query to MSSQL
$query = mssql_query('SELECT [username], [name], [email] FROM [php].[dbo].[userlist]');

echo 'Result set contains the following field(s):', PHP_EOL;

// Dump all field names in result
for ($i = 0; $i < mssql_num_fields($query); ++$i) {
    echo ' - ' . mssql_field_name($query, $i), PHP_EOL;
}

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

以上例程的输出类似于:

Result set contains the following field(s):
 - username
 - name
 - email

参见

mssql_field_length() - Get the length of a field mssql_field_type() - Gets the type of a field
add a note

User Contributed Notes 3 notes

up down 0 ian_channing at hotmail dot com5 years ago There is a limitation of 30 characters for the field name. So if your query has  `fieldname AS really_long_overly_descriptive_name`, you will only get `really_long_overly_descriptiv` back

<?php
// Send a select query to MSSQL
$query = mssql_query('SELECT [username] AS [really_long_overly_descriptive_name], [name], [email] FROM [php].[dbo].[userlist]');

echo 'Result set contains the following field(s):', PHP_EOL;

// Dump all field names in result
for ($i = 0; $i < mssql_num_fields($query); ++$i) {
    echo ' - ' . mssql_field_name($query, $i), PHP_EOL;
}

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

Outputs the following:

Result set contains the following field(s):
- really_long_overly_descriptiv
- name
- email
up down 0 harold at worby dot dns2go dot com17 years ago A simple script to walk through an MSSQL server.
I'm using PHP 4.06 and Freetds 5.1 on Solaris 2.7 and Apache 1.3
Several of the msql_ functions seem to be broken/missing.
This is what I found to work.

<?php
// --------------------------------------------------------
// URL http://server/mssqltest.php?DB=Database&table=TableName
// --------------------------------------------------------
// Default settings: edit to meet your needs
if (!($user)) $user=sa;
if (!($pass)) $pass="password";
if (!($host)) $host="acer900";
// --------------------------------------------------
// connect to mssql server
$connect = mssql_connect($host,$user,$pass) or die ($host." not accessible.");
// select the database
if ($DB) mssql_select_db($DB)or die('USE '.$DB.' failed!');
if (!($table)) {
    $query="EXEC sp_tables \"%\",\"%\",\"".$DB."\",\"'TABLE'\"";
    $linkcol=2;
    $linkcol="TABLE_NAME";
$linkformat=" <a href=\"%s?DB=".$DB."&table=%s\">%s</a> ";
}else{ // tables and DB - Get DATA
    $query="SELECT * FROM ".$table;
    $linkformat=" <a href=\"%s\">%s</a> ";
}
if (!($DB))    {
    $query="EXEC sp_databases";
    $linkcol=0;
    $linkcol="DATABASE_NAME";
    $linkformat="<a href=\"%s?DB=%s\">%s</a>";
}

// run query
echo $query."<br>";
$result = mssql_query( $query) or die('Query failed!');
$fields = mssql_num_fields ($result) or die("Num Fields Failed");
$rows   = mssql_num_rows ($result);

echo "<br>Rows ".$rows." Fields ".$fields."<br>";
echo "<TABLE border=1><tr>";
// get field names
for ( $f = 0 ; $f < $fields ; $f++ ){
    $name = mssql_fetch_field($result, $f);
    echo "<td>".$f.$name->name."</td>";
// Strange here.. without the "X"'s the () is always TRUE??
    if ($name->name."X" == $linkcol."X") $linkcol = $f;
}
echo "</tr>";
//Display Data
for ($i = 0; $i < $rows ; $i =$i +1){
    for ($f = 0; $f<$fields ; $f++){
        $name=mssql_result($result,$i,$f);
        if ($f == $linkcol){
printf("<td>".$linkformat."</td>\n",$PHP_SELF,
$name , $name );
        }
        else{
            echo "<td>". $name . "</td>";
        }
    }
echo "</tr>";
}
echo "</TABLE><br>";

// close connection
mssql_close ($connect);
?>
up down 0 tengel at sonic dot net18 years ago This function isn't supported (PHP 4.0.2) if using Sybase/FreeTDS to access SQLServer (linux/solaris/bsd/etc).  Instead, use "mssql_fetch_field()" like so:

$field_name = mssql_fetch_field($query_result, $field_number);
print $field_name->name;
add a note

官方地址:https://www.php.net/manual/en/function.mssql-field-name.php

  推荐站点

  • At-lib分类目录At-lib分类目录

    At-lib网站分类目录汇集全国所有高质量网站,是中国权威的中文网站分类目录,给站长提供免费网址目录提交收录和推荐最新最全的优秀网站大全是名站导航之家

    www.at-lib.cn
  • 中国链接目录中国链接目录

    中国链接目录简称链接目录,是收录优秀网站和淘宝网店的网站分类目录,为您提供优质的网址导航服务,也是网店进行收录推广,站长免费推广网站、加快百度收录、增加友情链接和网站外链的平台。

    www.cnlink.org
  • 35目录网35目录网

    35目录免费收录各类优秀网站,全力打造互动式网站目录,提供网站分类目录检索,关键字搜索功能。欢迎您向35目录推荐、提交优秀网站。

    www.35mulu.com
  • 就要爱网站目录就要爱网站目录

    就要爱网站目录,按主题和类别列出网站。所有提交的网站都经过人工审查,确保质量和无垃圾邮件的结果。

    www.912219.com
  • 伍佰目录伍佰目录

    伍佰网站目录免费收录各类优秀网站,全力打造互动式网站目录,提供网站分类目录检索,关键字搜索功能。欢迎您向伍佰目录推荐、提交优秀网站。

    www.wbwb.net