如何查询表的列名 [英] how to query the column names of a table
本文介绍了如何查询表的列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我需要关于显示特定表示例的列名的帮助我有一个名为 account 的表,它有 account_id、first_name、last_name 和类似的东西我需要显示 account_id、first_name、last_name 等等在而不是该列中的数据真的需要您的帮助..谢谢:)
Hi guys i need help about displaying a column name of a specific table example i have a table named account and it has account_id, first_name, last_name and stuffs like that what i need is to display the account_id, first_name, last_name and so on and not the data inside that column really need your help.. thanks :)
SELECT table_name, column_name, data_type, data_length
FROM USER_TAB_COLUMNS
WHERE table_name = 'mydatabase'
这是我在研究答案时发现的代码,但我不知道如何执行这个代码..我真的不知道我将如何使用它来显示列名..
that's the code i found while i was researching for answers but i don't know how to excecute this one.. i really have no idea how would i use this to display the column name..
推荐答案
$result = mysql_query("SHOW COLUMNS FROM sometable");
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
print_r($row);
}
}
结果可能:
Array
(
[Field] => id
[Type] => int(7)
[Null] =>
[Key] => PRI
[Default] =>
[Extra] => auto_increment
)
这篇关于如何查询表的列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文