How to get Column Name With Zend DB
How to get Column Name With Zend DB
Asked Answered
Perhaps you should describe a little bit what you're trying to do... Apikot's answer is a starting point though. –
Rayborn
This is the correct answer, the older answers are wrong or outdated:
$cols = $table->info(Zend_Db_Table_Abstract::COLS);
rewrote your intro-text since SO doesn't know 'bumping' and questions/answers are not considered old. in fact SO is a wiki and updating it is one of the best things you can do! +1 –
Brackish
$metadata = $db->describeTable($tableName);
$columnNames = array_keys($metadata);
http://framework.zend.com/manual/en/zend.db.html#zend.db.adapter.list-describe
That's not really 100% correct as $metadata is an associative array ('column_name' => array()) of associative arrays (one for each column of the table). –
Rayborn
add schame's name to $db->describeTable($tableName, $schema); , i just had an error using oracle which takes old column names if i had changed them and had to specify the schema for it to return right column names –
Zasuwa
Previous answer applies only to version < 2.
For current version of ZF (2.2) use:
$table = new Zend\Db\TableGateway\TableGateway('table', $Dbadapter, new Zend\Db\TableGateway\Feature\MetadataFeature());
$columns = $table->getColumns();
http://framework.zend.com/manual/2.2/en/modules/zend.db.table-gateway.html#tablegateway-features http://framework.zend.com/manual/2.2/en/modules/zend.db.metadata.html
© 2022 - 2024 — McMap. All rights reserved.