MySQL query to get column names?

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

    function get_col_names(){  
        $sql = "SHOW COLUMNS FROM tableName";  
        $result = mysql_query($sql);     
        while($record = mysql_fetch_array($result)){  
         $fields[] = $record['0'];  
        }
        foreach ($fields as $value){  
          echo 'column name is : '.$value.'-';  
    }  
     }  
    
    return get_col_names();
    

提交回复
热议问题