MySQL查询获取列名? [英] MySQL query to get column names?

查看:962
本文介绍了MySQL查询获取列名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将所有mysql表的col名称放入php数组中吗?

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

是否对此有疑问?

推荐答案

最好的方法是使用 INFORMATION_SCHEMA.COLUMNS 表...

The best way is to use the INFORMATION_SCHEMA metadata virtual database. Specifically the INFORMATION_SCHEMA.COLUMNS table...

SELECT `COLUMN_NAME` 
FROM `INFORMATION_SCHEMA`.`COLUMNS` 
WHERE `TABLE_SCHEMA`='yourdatabasename' 
    AND `TABLE_NAME`='yourtablename';

它非常强大,可以在不解析文本的情况下为您提供大量信息(例如列类型,列是否可为空,最大列大小,字符集等)...

It's VERY powerful, and can give you TONS of information without need to parse text (Such as column type, whether the column is nullable, max column size, character set, etc)...

哦,它是标准的SQL(而SHOW ...是MySQL特定的扩展名)...

Oh, and it's standard SQL (Whereas SHOW ... is a MySQL specific extension)...

有关SHOW...与使用INFORMATION_SCHEMA表之间区别的更多信息,请查看MySQL

For more information about the difference between SHOW... and using the INFORMATION_SCHEMA tables, check out the MySQL Documentation on INFORMATION_SCHEMA in general...

这篇关于MySQL查询获取列名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆