2012-02-11 50 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