How to get metadata from query result,.? I wanna get the datatype of each column from my query result,.
Asked
Active
Viewed 546 times
0
-
What do you mean saying query result? `$table->fetchAll()` which returns `Zend_Db_Table_Rowset` ? Look here http://stackoverflow.com/questions/708782/how-to-get-column-name-with-zend-db – Radek Benkel Nov 25 '11 at 11:18
-
you right @singles , on that link, I can't find an answer for my question,. – Praditha Dec 05 '11 at 03:49
1 Answers
1
singles linked to a helpful post in his comment, but more specifically, here is how you can get the data type for a column from your table.
// $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']);
For each column in your table, you will have an array of data like so:
["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)
}

drew010
- 68,777
- 11
- 134
- 162