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

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

问题描述

我想在 php 中将所有 mysql 表的列名放入一个数组中?

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

有这方面的查询吗?

推荐答案

最好的方法是使用 INFORMATION_SCHEMA 元数据虚拟数据库.特别是 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 关于INFORMATION_SCHEMA 的一般文档...

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天全站免登陆