WARNING: as of PHP 4.3.2
Only returns 1st 30 characters of fieldname.
mssql_field_name
(PHP 4, PHP 5, PECL odbtp:1.1.1-1.1.4)
mssql_field_name — Get the name of a field
Popis
string mssql_field_name ( resource $result [, int $offset] )Returns the name of field no. offset in result.
Seznam parametrů
- 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.
Návratové hodnoty
The name of the specified field index on success, or FALSE on failure.
Viz také
| mssql_field_length() |
| mssql_field_type() |
mssql_field_name
php at electricsurfer dot com
03-Jun-2003 12:18
03-Jun-2003 12:18
harold at worby dot dns2go dot com
06-Mar-2002 01:29
06-Mar-2002 01:29
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);
?>
tengel at sonic dot net
07-Oct-2000 07:43
07-Oct-2000 07:43
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;
