mysql_field_name
PHP function
Edit on GitHub ✎
(PHP 4, PHP 5)
Get the name of the specified field in a result
Note mysqli_fetch_field_direct [name] or [orgname]PDOStatement::getColumnMeta [name]
Description
mysql_field_name(resource $result, int $field_offset): string|false
mysql_field_name() returns the name of the specified field index.
Parameters
Return Values
The name of the specified field index on successFalseforfailure.
Examples
mysql_field_name() example
php
<?php
/* The users table consists of three fields:
* user_id
* username
* password.
*/
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect to MySQL server: ' . mysql_error());
}
$dbname = 'mydb';
$db_selected = mysql_select_db($dbname, $link);
if (!$db_selected) {
die("Could not set $dbname: " . mysql_error());
}
$res = mysql_query('select * from users', $link);
echo mysql_field_name($res, 0) . "\n";
echo mysql_field_name($res, 2);
?>The above example will output:
output
user_id
passwordNotes Field-case
Note
Alias mysql_fieldname()