2011-11-25 56 views
0

如何从查询结果中获取元数据? 我想从我的查询结果中获取每列的数据类型。如何使用zend获取元数据结果集

+0

你的意思是说查询结果? '$ table-> fetchAll()'返回'Zend_Db_Table_Rowset'?看看这里http://stackoverflow.com/questions/708782/how-to-get-column-name-with-zend-db – singles

+0

你正确@singles,在那个链接,我找不到我的问题的答案, 。 – Praditha

回答

1

单击链接到他的评论中有用的帖子,但更具体地说,这里是如何从表中获取列的数据类型。

// $tbl is your Zend_Db_Table object 
$info = $tbl->info(Zend_Db_Table_Abstract::METADATA); // get the table metadata, fetches it if it is not yet set 

// get the data type for the "email_address" column 
$type = $info['email_address']['DATA_TYPE']); 

为表中的每一列,你将有数据的这样一个数组:

["column_name"] => 
    array(14) { 
    ["SCHEMA_NAME"]=> NULL 
    ["TABLE_NAME"]=> string(8) "accounts" 
    ["COLUMN_NAME"]=> string(10) "account_id" 
    ["COLUMN_POSITION"]=> int(1) 
    ["DATA_TYPE"]=> string(9) "mediumint" 
    ["DEFAULT"]=> NULL 
    ["NULLABLE"]=> bool(false) 
    ["LENGTH"]=> NULL 
    ["SCALE"]=> NULL 
    ["PRECISION"]=> NULL 
    ["UNSIGNED"]=> bool(true) 
    ["PRIMARY"]=> bool(true) 
    ["PRIMARY_POSITION"]=> int(1) 
    ["IDENTITY"]=> bool(true) 

}

相关问题