PHP Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
PHP Topics
Introduction Introduction
Syntax Syntax
Data Types Data Types
Operators Operators
Control Structures Control Structures
Functions Functions
Pre-defined Function Pre-defined Function
Calendar Functions Calendar Functions
Date and Time Date and Time
Array Functions Array Functions
Array List Array Functions List1
Array Function List Array Functions List2
Math Functions Math Functions
PHP MYSQL Functions PHP Mysql Functions
File Handling File Handling
Error Handling Error Handling
DB Size DB Size
PHP Mail PHP Mail
String Tokens String Tokens
String Functions String Functions
String Functions List String Functions List1
String Functions List2 String Functions List2
Session Functions Session Functions
Cookies Functions Cookies Functions
Form Variables Form Variables
Running PHP from JS Running PHP from JS
Array To JS Array To JS
JS Array Array to PHP
Encryption Encryption
Common Header Common Header
Forums Ask Your Doubts
Scraps More about PHP
Feedback Feedback
 




mysql_list_fields() function in PHP


Tutorials »Php »

Topic

What is mysql_list_fields() function in PHP?
How does mysql_list_fields() works?




Explanation

The mysql_list_fields() function list given MySQL table fields.

Syntax
resource mysql_list_fields ( string database_name, string table_name [, resource link_identifier])

Returns result pointer resource on success, or FALSE on failure.

mysql_list_fields() retrieves information about the given table name, when the database and the table name is passed as arguments. This function returns a result pointer to retrieve field information, which can be used with mysql_field_flags() to list field flags of the specified field, mysql_field_len() to list maximum length of the specified field, mysql_field_name() to list name of the specified field index, and mysql_field_type() to list field type of specified fields.

This function is deprecated. It is preferable to use mysql_query() function to execute SQL query 'SHOW COLUMNS FROM table_name [LIKE 'name'] to retrieve field information of given table .

Example


<?php

//Attempt to connect to the default database server
$link = mysql_connect("mysql_host", "mysql_user", "mysql_password")
or die ("Could not connect");

//returns result pointer of field informatin
$fields = mysql_list_fields("database1", "table1", $link);

//returns number of fields
$columns = mysql_num_fields($fields);

//list name of fields returned by result pointer
for ($i = 0; $i < $columns; $i++) {
echo mysql_field_name($fields, $i) . "\n";
}

?>



Above code returns a result pointer to retrieve field information using mysql_list_fields function for a given connection $link. mysql_num_fields function is used to fetch the number of returned fields and fields names returned by result pointer is listed by using mysql_field_name function.

RESULT:

field1
field2
field3...






Other Links

web hosting