MySQL query to get column names?

前端 未结 21 2431
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 01:56

I\'d like to get all of a mysql table\'s col names into an array in php?

Is there a query for this?

21条回答
  •  耶瑟儿~
    2020-11-22 02:40

    You can use following query for MYSQL:

    SHOW columns FROM your-table;
    

    Below is the example code which shows How to implement above syntax in php to list the names of columns:

    $sql = "SHOW COLUMNS FROM your-table";
    $result = mysqli_query($conn,$sql);
    while($row = mysqli_fetch_array($result)){
        echo $row['Field']."
    "; }

    For Details about output of SHOW COLUMNS FROM TABLE visit: MySQL Refrence.

提交回复
热议问题