douqiandai4327 2017-07-25 15:21
浏览 59
已采纳

使用php循环使用MSSQL表的每个列名

If I have [x] [y] [z] columns inside a [mytable] table in MSSQL, I would like to know how can I loop through each of them using php in order to have all of the columns' name? The reason is because I could potentially delete or add a column so that php code would make this dynamic without having to hardcode the php page. Basically, if I could have a php code similar to the following,

foreach( COLUMN as $columname in [SQL table]) 
    echo "$columname";
    // do something else
}

it would be awesome.

  • 写回答

2条回答 默认 最新

  • dongzhuo3376 2017-07-25 15:26
    关注

    Select the data from the INFORMATION_SCHEMA.COLUMNS system view. Filtered on your table name.

    select column_name 
    from information_schema.columns
    where table_name = 'mytable'
    

    Returns

    Column_name
    -----------
    x
    y
    z
    

    This gives you a resultset containing all column names, loop through and use the values.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀