2012-02-11 66 views
0

我想从当前数据库中所有表及其列的列表,如:获得从sqlite的DB信息架构

table1 
    - column1 
    - column2 
    - column3 
table2 
    - column1 
    - column2 

我想:

SELECT * FROM sqlite_master WHERE type=? ORDER BY name;

?'table'

但我只得到表列表,没有列:(

如果我删除了WHERE子句我得到这个错误:

SQLSTATE[HY000]: General error: 25 bind or column index out of range 

如果我更换tablecolumn我什么也得不到......

帮助吗?

回答

2

尝试此查询:

pragma table_info(table1); 

你会得到以下几列:

cid // Column Id 
name // Column Name 
type // Column Type 
notnull // If the column is not null 
dflt_value // Column default Value 
pk // If the column is a primary key 
+0

我得到的25错误 – Alex 2012-02-11 22:02:14

+0

你在PHP中使用的SQLite PDO? – iDifferent 2012-02-11 22:07:37

+0

是的。但它现在有效,问题是我的查询包装函数没有传递正确的参数:) – Alex 2012-02-11 22:10:55