MySQL query to get column names?

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

    Use mysql_fetch_field() to view all column data. See manual.

    $query = 'select * from myfield';
    $result = mysql_query($query);
    $i = 0;
    while ($i < mysql_num_fields($result))
    {
       $fld = mysql_fetch_field($result, $i);
       $myarray[]=$fld->name;
       $i = $i + 1;
    }
    

    "Warning This extension is deprecated as of PHP 5.5.0, and will be removed in the future."

提交回复
热议问题