从sqlite db获取信息模式

时间:2012-02-11 21:43:43

标签: php sql sqlite pdo information-schema

我想从当前数据库中获取所有表及其列的列表,例如:

 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

如果我将table替换为column,我什么也得不到......

请帮忙吗?

1 个答案:

答案 0 :(得分:3)

尝试此查询:

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
相关问题