如何从sqlite 3中的给定表中获取所有列名的列表? (表可能是空的)

时间:2010-07-19 15:00:35

标签: php sqlite

现在我使用:

PRAGMA table_info(table_name)

构造,但它不允许我将搜索结果缩小到仅列名称,因为它会导致大量不需要的数据。那是数组数组

Array
(
    [0] => Array
        (
            [cid] => 0
            [name] => id
            [type] => INTEGER
            [notnull] => 0
            [dflt_value] => 
            [pk] => 1
        )

    [1] => Array
        (
            [cid] => 1
            [name] => name
            [type] => TEXT
            [notnull] => 0
            [dflt_value] => 
            [pk] => 0
        )

    [2] => Array
        (
            [cid] => 2
            [name] => timestamp
            [type] => INTEGER
            [notnull] => 0
            [dflt_value] => 
            [pk] => 0
        )

    [3] => Array
        (
            [cid] => 3
            [name] => note
            [type] => TEXT
            [notnull] => 0
            [dflt_value] => 
            [pk] => 0
        )

)

结果

会更好
Array
(
    [0] => id
    [1] => title
    [2] => timestamp
    [3] => note
)

但PRAGMA table_info(table_name)中的SELECT name不起作用

1 个答案:

答案 0 :(得分:1)

您无法更改table_info的输出,但循环结果对象并构建所需的列名称数组非常简单。