How does php obtain the Access field name?

Source: Internet
Author: User
How can I obtain the Access field name in php? today, I have obtained the Access database data, but how can I obtain the table field name? & nbsp; I have obtained all the fields in the table without displaying numbers & nbsp; how can I obtain the Access field name in php?
Today, I have obtained the data used in the Access Database. but how can I obtain the table field name?

All the obtained fields are numerical fields that do not display table names.


// ================================================ ======================================
// Get record list
// Obtain the record list
// ================================================ ======================================
Public function getlist ($ table, $ field, $ fieldnum, $ condition = "", $ sort = "") // retrieves the record list
{
$ SQL = "SELECT". $ field. "FROM". $ table. "". $ condition. "". $ sort;
$ Query = $ this-> query ($ SQL );
$ I = 0;
While ($ this-> fetch_row ($ query ))
{
For ($ j = 0; $ j <$ fieldnum; $ j ++)
{
$ Info [$ j] = odbc_result ($ query, $ j + 1 );
}
$ Rdlist [$ I] = $ info;
$ I ++;
}
Return $ rdlist;
}


This is my method.

------ Solution --------------------
I have never used odbc. check whether there are any methods like mysql_fetch_array () mysql_fetch_assoc (). you can directly use the field name in the table.
------ Solution --------------------
Odbc_field_name

------ Solution --------------------
The mysql_list_fields () function returns the field name of the table.
------ Solution --------------------
Odbc_fetch_into
------ Solution --------------------

$ Connstr = "DRIVER = Microsoft Access Driver (*. mdb); DBQ =". realpath ("cust. mdb ");
$ Conn = odbc_connect ($ connstr, "", "", SQL _CUR_USE_ODBC );

$ Query = odbc_do ($ conn, "select * from yhxx ");

// Output record
While (odbc_fetch_row ($ query ))
{
$ Id = odbc_result ($ query, id );
$ Gonghao = odbc_result ($ query, gonghao );
Echo $ id;
Echo"
";
Echo $ gonghao;
Echo"
";
}

// Output field

$ Num_field = max (odbc_num_fields ($ query), $ num_field );
For ($ I = 0; $ I
Echo @ odbc_field_name ($ query, $ I + 1 );
Echo"
";
}

Odbc_close ($ conn );



?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.