MySQL query to get column names?

前端 未结 21 2149
伪装坚强ぢ
伪装坚强ぢ 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:49

    i no expert, but this works for me..

    $sql = "desc MyTable";
    $result = @mysql_query($sql);
    while($row = @mysql_fetch_array($result)){
        echo $row[0]."
    "; // returns the first column of array. in this case Field // the below code will return a full array-> Field,Type,Null,Key,Default,Extra // for ($c=0;$c";} }

提交回复
热议问题